<template>
  <div class="workflow-settings">
    <!-- 页面头部 -->
    <div class="page-header">
      <h1 class="page-title">工作流程设置</h1>
      <p class="page-description">可视化配置案件处理流程、期限管理和消息通知</p>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 左侧导航 -->
      <div class="sidebar">
        <div class="nav-menu">
          <div 
            v-for="module in modules" 
            :key="module.id"
            :class="['nav-item', { active: activeModule === module.id }]"
            @click="switchModule(module.id)"
          >
            <i :class="module.icon"></i>
            <span>{{ module.name }}</span>
          </div>
        </div>
      </div>

      <!-- 右侧内容区 -->
      <div class="content-area">
        <!-- 可视化流程设计器 -->
        <div v-show="activeModule === 'process'" class="module-content">
          <div class="module-header">
            <h2>可视化流程设计器</h2>
            <p>通过拖拽方式设计业务流程图</p>
            <div class="header-actions">
              <el-select v-model="selectedTemplate" placeholder="选择流程模板" style="width: 200px; margin-right: 12px;">
                <el-option 
                  v-for="template in processTemplates" 
                  :key="template.id"
                  :label="template.name" 
                  :value="template.id"
                />
              </el-select>
              <el-button @click="loadTemplate">
                <i class="el-icon-download"></i>
                加载模板
              </el-button>
              <el-button type="primary" @click="saveWorkflow">
                <i class="el-icon-check"></i>
                保存流程
              </el-button>
              <el-button @click="previewWorkflow">
                <i class="el-icon-view"></i>
                预览
              </el-button>
            </div>
          </div>

          <!-- 流程设计器 -->
          <div class="workflow-designer">
            <!-- 节点工具栏 -->
            <div class="node-toolbar">
              <div class="toolbar-section">
                <h4>节点类型</h4>
                <div class="node-buttons">
                  <el-button 
                    v-for="nodeType in nodeTypes" 
                    :key="nodeType.type"
                    @click="addNode(nodeType.type)"
                    :class="['node-btn', nodeType.type]"
                  >
                    <i :class="nodeType.icon"></i>
                    {{ nodeType.label }}
                  </el-button>
                </div>
              </div>
              
              <div class="toolbar-section">
                <h4>操作工具</h4>
                <div class="tool-buttons">
                  <el-button @click="clearCanvas">
                    <i class="el-icon-delete"></i>
                    清空画布
                  </el-button>
                  <el-button @click="autoLayout">
                    <i class="el-icon-s-grid"></i>
                    自动布局
                  </el-button>
                  <el-button @click="zoomIn">
                    <i class="el-icon-zoom-in"></i>
                  </el-button>
                  <el-button @click="zoomOut">
                    <i class="el-icon-zoom-out"></i>
                  </el-button>
                </div>
              </div>
            </div>
            
            <!-- 画布区域 -->
            <div class="workflow-canvas" ref="canvas" @click="deselectAll">
              <!-- 网格背景 -->
              <div class="canvas-grid"></div>
              
              <!-- 流程节点 -->
              <div 
                v-for="node in workflowNodes" 
                :key="node.id"
                class="workflow-node"
                :class="[node.type, { selected: selectedNode === node.id }]"
                :style="{ 
                  left: node.x + 'px', 
                  top: node.y + 'px',
                  transform: `scale(${zoomLevel})`
                }"
                @click.stop="selectNode(node.id)"
                @mousedown="startNodeDrag($event, node)"
              >
                <div class="node-header">
                  <i :class="getNodeIcon(node.type)" class="node-icon"></i>
                  <span class="node-title">{{ node.title || getNodeLabel(node.type) }}</span>
                  <el-button 
                    size="mini" 
                    type="danger" 
                    icon="el-icon-close"
                    @click.stop="deleteNode(node.id)"
                    class="delete-btn"
                  />
                </div>
                
                <div class="node-body" v-if="node.description">
                  <p class="node-description">{{ node.description }}</p>
                </div>
                
                <div class="node-footer" v-if="node.type === 'process'">
                  <div class="node-meta">
                    <span v-if="node.responsible" class="responsible">
                      <i class="el-icon-user"></i>{{ getResponsibleName(node.responsible) }}
                    </span>
                    <span v-if="node.duration" class="duration">
                      <i class="el-icon-time"></i>{{ node.duration }}
                    </span>
                  </div>
                </div>
                
                <!-- 连接点 -->
                <div class="connection-points">
                  <div 
                    v-if="node.type !== 'start'" 
                    class="connection-point input"
                    @mousedown.stop="startConnection(node.id, 'input')"
                  ></div>
                  <div 
                    v-if="node.type !== 'end'" 
                    class="connection-point output"
                    @mousedown.stop="startConnection(node.id, 'output')"
                  ></div>
                </div>
              </div>
              
              <!-- 连接线 -->
              <svg class="connections-layer" :style="{ transform: `scale(${zoomLevel})` }">
                <defs>
                  <marker id="arrowhead" markerWidth="10" markerHeight="7" 
                    refX="9" refY="3.5" orient="auto">
                    <polygon points="0 0, 10 3.5, 0 7" fill="#409eff" />
                  </marker>
                </defs>
                <path 
                  v-for="connection in connections" 
                  :key="connection.id"
                  :d="getConnectionPath(connection)"
                  stroke="#409eff" 
                  stroke-width="2"
                  fill="none"
                  marker-end="url(#arrowhead)"
                  @click="selectConnection(connection.id)"
                  :class="{ selected: selectedConnection === connection.id }"
                />
              </svg>
              
              <!-- 临时连接线 -->
              <svg v-if="tempConnection" class="temp-connection">
                <line 
                  :x1="tempConnection.x1" 
                  :y1="tempConnection.y1"
                  :x2="tempConnection.x2" 
                  :y2="tempConnection.y2"
                  stroke="#409eff" 
                  stroke-width="2"
                  stroke-dasharray="5,5"
                />
              </svg>
            </div>
            
            <!-- 属性面板 -->
            <div class="property-panel" v-if="selectedNode">
              <h4>节点属性</h4>
              <el-form :model="selectedNodeData" label-width="80px" size="small">
                <el-form-item label="节点名称">
                  <el-input v-model="selectedNodeData.title" placeholder="请输入节点名称" />
                </el-form-item>
                
                <el-form-item label="描述">
                  <el-input 
                    v-model="selectedNodeData.description" 
                    type="textarea" 
                    :rows="3"
                    placeholder="请输入节点描述"
                  />
                </el-form-item>
                
                <el-form-item label="责任人" v-if="selectedNodeData.type === 'process'">
                  <el-select v-model="selectedNodeData.responsible" placeholder="选择责任人">
                    <el-option label="主办律师" value="primary_lawyer" />
                    <el-option label="协办律师" value="assistant_lawyer" />
                    <el-option label="律师助理" value="paralegal" />
                    <el-option label="客服专员" value="customer_service" />
                    <el-option label="财务专员" value="finance_staff" />
                  </el-select>
                </el-form-item>
                
                <el-form-item label="预计用时" v-if="selectedNodeData.type === 'process'">
                  <el-input v-model="selectedNodeData.duration" placeholder="如：1-2天" />
                </el-form-item>
                
                <el-form-item label="判断条件" v-if="selectedNodeData.type === 'decision'">
                  <el-input 
                    v-model="selectedNodeData.condition" 
                    placeholder="请输入判断条件"
                  />
                </el-form-item>
                
                <el-form-item label="通知设置">
                  <el-checkbox-group v-model="selectedNodeData.notifications">
                    <el-checkbox label="email">邮件</el-checkbox>
                    <el-checkbox label="sms">短信</el-checkbox>
                    <el-checkbox label="system">系统</el-checkbox>
                    <el-checkbox label="wechat">微信</el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
                
                <el-form-item>
                  <el-button type="primary" size="small" @click="updateNodeData">
                    更新节点
                  </el-button>
                  <el-button size="small" @click="deselectNode">
                    取消选择
                  </el-button>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>

        <!-- 流程期限管理 -->
        <div v-show="activeModule === 'deadline'" class="module-content">
          <div class="module-header">
            <h2>流程期限管理</h2>
            <p>根据各个业务流程设置期限要求，流程期间期限以及期限提醒</p>
            <div class="header-actions">
              <el-button type="primary" @click="addDeadlineRule">
                <i class="el-icon-plus"></i>
                新增期限规则
              </el-button>
              <el-button @click="batchSetDeadlines">
                <i class="el-icon-setting"></i>
                批量设置
              </el-button>
              <el-button @click="viewDeadlineStats">
                <i class="el-icon-data-analysis"></i>
                期限统计
              </el-button>
            </div>
          </div>

          <!-- 期限规则表格 -->
          <div class="deadline-table">
            <el-table :data="deadlineRules" style="width: 100%">
              <el-table-column prop="processName" label="业务流程" width="200">
                <template #default="scope">
                  <div class="process-info">
                    <i :class="getProcessIcon(scope.row.processType)"></i>
                    <span>{{ scope.row.processName }}</span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="deadlineRequirement" label="期限要求" width="150">
                <template #default="scope">
                  <el-tag :type="getDeadlineType(scope.row.urgency)">
                    {{ scope.row.deadlineRequirement }}天
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="reminderTime" label="提醒时间" width="120">
                <template #default="scope">
                  <span>提前{{ scope.row.reminderTime }}天</span>
                </template>
              </el-table-column>
              <el-table-column prop="reminderEnabled" label="提醒设置" width="150">
                <template #default="scope">
                  <div class="reminder-config">
                    <el-tag 
                      :type="scope.row.reminderEnabled ? 'success' : 'info'"
                      size="small"
                    >
                      {{ scope.row.reminderEnabled ? '已启用' : '已禁用' }}
                    </el-tag>
                    <el-button 
                      v-if="scope.row.reminderEnabled"
                      size="mini" 
                      type="text" 
                      @click="configureNotification(scope.row)"
                    >
                      配置通知
                    </el-button>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="escalation" label="升级设置" width="120">
                <template #default="scope">
                  <el-switch 
                    v-model="scope.row.escalationEnabled"
                    @change="updateEscalation(scope.row)"
                  />
                </template>
              </el-table-column>
              <el-table-column prop="status" label="状态" width="100">
                <template #default="scope">
                  <el-tag 
                    :type="scope.row.status === 'active' ? 'success' : 'info'"
                    size="small"
                  >
                    {{ scope.row.status === 'active' ? '启用' : '禁用' }}
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column label="操作" width="200" fixed="right">
                <template #default="scope">
                  <el-button size="small" @click="editDeadlineRule(scope.row)">
                    编辑
                  </el-button>
                  <el-button size="small" @click="testReminder(scope.row)">
                    测试提醒
                  </el-button>
                  <el-button 
                    size="small" 
                    type="danger" 
                    @click="deleteDeadlineRule(scope.row)"
                  >
                    删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>

          <!-- 期限统计卡片 -->
          <div class="deadline-stats">
            <div class="stat-cards">
              <div class="stat-card">
                <div class="stat-icon warning">
                  <i class="el-icon-warning"></i>
                </div>
                <div class="stat-content">
                  <div class="stat-number">{{ deadlineStats.overdue }}</div>
                  <div class="stat-label">超期案件</div>
                </div>
              </div>
              <div class="stat-card">
                <div class="stat-icon danger">
                  <i class="el-icon-bell"></i>
                </div>
                <div class="stat-content">
                  <div class="stat-number">{{ deadlineStats.approaching }}</div>
                  <div class="stat-label">临期提醒</div>
                </div>
              </div>
              <div class="stat-card">
                <div class="stat-icon success">
                  <i class="el-icon-success"></i>
                </div>
                <div class="stat-content">
                  <div class="stat-number">{{ deadlineStats.onTime }}</div>
                  <div class="stat-label">按时完成</div>
                </div>
              </div>
              <div class="stat-card">
                <div class="stat-icon info">
                  <i class="el-icon-data-analysis"></i>
                </div>
                <div class="stat-content">
                  <div class="stat-number">{{ deadlineStats.avgDays }}</div>
                  <div class="stat-label">平均用时(天)</div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 消息通知管理 -->
        <div v-show="activeModule === 'notification'" class="module-content">
          <div class="module-header">
            <h2>消息通知管理</h2>
            <p>可根据业务节点排定通知主体，通知信息模板编辑</p>
            <div class="header-actions">
              <el-button type="primary" @click="addNotificationRule">
                <i class="el-icon-plus"></i>
                新增通知规则
              </el-button>
              <el-button @click="manageTemplates">
                <i class="el-icon-document"></i>
                模板管理
              </el-button>
              <el-button @click="testNotification">
                <i class="el-icon-message"></i>
                测试通知
              </el-button>
            </div>
          </div>

          <!-- 通知规则配置 -->
          <div class="notification-config">
            <div class="config-grid">
              <!-- 业务节点选择 -->
              <div class="config-section">
                <h3>业务节点配置</h3>
                <div class="node-selector">
                  <div 
                    v-for="node in businessNodes" 
                    :key="node.id"
                    :class="['node-item', { selected: selectedNodes.includes(node.id) }]"
                    @click="toggleNodeSelection(node.id)"
                  >
                    <div class="node-info">
                      <i :class="node.icon"></i>
                      <span>{{ node.name }}</span>
                    </div>
                    <div class="node-events">
                      <el-tag 
                        v-for="event in node.events" 
                        :key="event"
                        size="mini"
                      >
                        {{ getEventName(event) }}
                      </el-tag>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 通知对象配置 -->
              <div class="config-section">
                <h3>通知对象</h3>
                <div class="recipient-config">
                  <div class="recipient-groups">
                    <div 
                      v-for="group in recipientGroups" 
                      :key="group.id"
                      class="recipient-group"
                    >
                      <div class="group-header">
                        <el-checkbox 
                          v-model="group.selected"
                          @change="toggleRecipientGroup(group)"
                        >
                          {{ group.name }}
                        </el-checkbox>
                        <span class="member-count">{{ group.members.length }}人</span>
                      </div>
                      <div v-show="group.selected" class="group-members">
                        <el-checkbox-group v-model="group.selectedMembers">
                          <el-checkbox 
                            v-for="member in group.members" 
                            :key="member.id"
                            :label="member.id"
                          >
                            {{ member.name }} ({{ member.role }})
                          </el-checkbox>
                        </el-checkbox-group>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 通知方式配置 -->
              <div class="config-section">
                <h3>通知方式</h3>
                <div class="notification-methods">
                  <div 
                    v-for="method in notificationMethods" 
                    :key="method.id"
                    :class="['method-item', { selected: selectedMethods.includes(method.id) }]"
                    @click="toggleMethodSelection(method.id)"
                  >
                    <div class="method-icon">
                      <i :class="method.icon"></i>
                    </div>
                    <div class="method-info">
                      <div class="method-name">{{ method.name }}</div>
                      <div class="method-desc">{{ method.description }}</div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 消息模板配置 -->
              <div class="config-section full-width">
                <h3>消息模板</h3>
                <div class="template-editor">
                  <div class="template-tabs">
                    <div 
                      v-for="template in messageTemplates" 
                      :key="template.id"
                      :class="['template-tab', { active: activeTemplate === template.id }]"
                      @click="switchTemplate(template.id)"
                    >
                      {{ template.name }}
                    </div>
                    <el-button size="small" @click="addTemplate">
                      <i class="el-icon-plus"></i>
                    </el-button>
                  </div>
                  
                  <div class="template-content">
                    <div class="template-form">
                      <el-form :model="currentTemplate" label-width="80px">
                        <el-form-item label="模板名称">
                          <el-input v-model="currentTemplate.name" />
                        </el-form-item>
                        <el-form-item label="消息标题">
                          <el-input v-model="currentTemplate.title" />
                        </el-form-item>
                        <el-form-item label="消息内容">
                          <el-input 
                            v-model="currentTemplate.content" 
                            type="textarea" 
                            :rows="6"
                            placeholder="可使用变量：{{案件编号}}、{{当事人}}、{{节点名称}}、{{操作人}}、{{时间}}"
                          />
                        </el-form-item>
                      </el-form>
                    </div>
                    
                    <div class="template-preview">
                      <h4>预览效果</h4>
                      <div class="preview-content">
                        <div class="preview-title">{{ getPreviewTitle() }}</div>
                        <div class="preview-body">{{ getPreviewContent() }}</div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <!-- 保存按钮 -->
            <div class="config-actions">
              <el-button type="primary" @click="saveNotificationConfig">
                <i class="el-icon-check"></i>
                保存配置
              </el-button>
              <el-button @click="previewNotification">
                <i class="el-icon-view"></i>
                预览通知
              </el-button>
              <el-button @click="resetConfig">
                <i class="el-icon-refresh"></i>
                重置
              </el-button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 对话框组件 -->
    <!-- 节点编辑对话框 -->
    <el-dialog 
      v-model="nodeDialogVisible" 
      title="编辑节点" 
      width="600px"
    >
      <el-form :model="editingNode" label-width="100px">
        <el-form-item label="节点名称" required>
          <el-input v-model="editingNode.name" />
        </el-form-item>
        <el-form-item label="节点类型" required>
          <el-select v-model="editingNode.type" style="width: 100%">
            <el-option label="开始节点" value="start" />
            <el-option label="审批节点" value="approval" />
            <el-option label="处理节点" value="process" />
            <el-option label="决策节点" value="decision" />
            <el-option label="结束节点" value="end" />
          </el-select>
        </el-form-item>
        <el-form-item label="执行角色" required>
          <el-select v-model="editingNode.executor" style="width: 100%">
            <el-option label="案件管理员" value="admin" />
            <el-option label="业务员" value="officer" />
            <el-option label="审批员" value="approver" />
            <el-option label="质检员" value="inspector" />
          </el-select>
        </el-form-item>
        <el-form-item label="预计天数">
          <el-input-number v-model="editingNode.estimatedDays" :min="1" :max="30" />
        </el-form-item>
        <el-form-item label="节点描述">
          <el-input v-model="editingNode.description" type="textarea" :rows="3" />
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="nodeDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="saveNode">保存</el-button>
      </template>
    </el-dialog>

    <!-- 期限规则对话框 -->
    <el-dialog 
      v-model="deadlineDialogVisible" 
      title="期限规则设置" 
      width="700px"
    >
      <el-form :model="editingDeadline" label-width="120px">
        <el-form-item label="业务流程" required>
          <el-select v-model="editingDeadline.processId" style="width: 100%">
            <el-option 
              v-for="process in processCategories" 
              :key="process.id"
              :label="process.name" 
              :value="process.id" 
            />
          </el-select>
        </el-form-item>
        <el-form-item label="期限要求" required>
          <el-input-number 
            v-model="editingDeadline.deadlineRequirement" 
            :min="1" 
            :max="365"
            style="width: 200px"
          />
          <span style="margin-left: 10px">天</span>
        </el-form-item>
        <el-form-item label="提醒时间">
          <el-input-number 
            v-model="editingDeadline.reminderTime" 
            :min="1" 
            :max="30"
            style="width: 200px"
          />
          <span style="margin-left: 10px">天前提醒</span>
        </el-form-item>
        <el-form-item label="启用提醒">
          <el-switch 
            v-model="editingDeadline.reminderEnabled"
            active-text="启用"
            inactive-text="禁用"
          />
          <div class="reminder-note">
            <el-text type="info" size="small">
              具体的通知方式请在"消息通知管理"中统一配置
            </el-text>
          </div>
        </el-form-item>
        <el-form-item label="升级设置">
          <el-switch v-model="editingDeadline.escalationEnabled" />
          <span style="margin-left: 10px">超期自动升级</span>
        </el-form-item>
        <el-form-item label="优先级">
          <el-radio-group v-model="editingDeadline.urgency">
            <el-radio label="low">低</el-radio>
            <el-radio label="normal">普通</el-radio>
            <el-radio label="high">高</el-radio>
            <el-radio label="urgent">紧急</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="deadlineDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="saveDeadlineRule">保存</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { ref, reactive, computed, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'

export default {
  name: 'WorkflowSettings',
  setup() {
    // 响应式数据
    const activeModule = ref('process')
    const nodeDialogVisible = ref(false)
    const deadlineDialogVisible = ref(false)
    
    // 模块配置
    const modules = ref([
      {
        id: 'process',
        name: '流程管理',
        icon: 'el-icon-s-operation'
      },
      {
        id: 'deadline',
        name: '流程期限管理',
        icon: 'el-icon-alarm-clock'
      },
      {
        id: 'notification',
        name: '消息通知管理',
        icon: 'el-icon-bell'
      }
    ])

    // 可视化流程设计器数据
    const selectedTemplate = ref('')
    const workflowNodes = ref([])
    const connections = ref([])
    const selectedNode = ref(null)
    const selectedConnection = ref(null)
    const selectedNodeData = ref({})
    const zoomLevel = ref(1)
    const tempConnection = ref(null)
    const draggedNode = ref(null)
    const isConnecting = ref(false)
    const connectionStart = ref(null)
    const canvas = ref(null)
    let nodeIdCounter = 1
    let connectionIdCounter = 1
    
    // 节点类型定义
    const nodeTypes = ref([
      {
        type: 'start',
        label: '开始',
        icon: 'el-icon-video-play',
        color: '#67c23a'
      },
      {
        type: 'process',
        label: '处理',
        icon: 'el-icon-s-operation',
        color: '#409eff'
      },
      {
        type: 'decision',
        label: '决策',
        icon: 'el-icon-question',
        color: '#e6a23c'
      },
      {
        type: 'end',
        label: '结束',
        icon: 'el-icon-video-pause',
        color: '#f56c6c'
      }
    ])
    
    // 流程模板
    const processTemplates = ref([
      {
        id: 'traffic_accident_template',
        name: '交通事故处理流程',
        description: '适用于交通事故人身损害赔偿案件的标准化处理流程',
        category: 'traffic',
        difficulty: 'medium',
        estimatedDays: 35,
        author: '王德华律师',
        lastUpdated: '2024-01-15',
        usage: 156,
        icon: 'el-icon-truck',
        tags: ['交通事故', '人身损害', '保险理赔']
      },
      {
        id: 'contract_dispute_template',
        name: '合同纠纷处理流程',
        description: '处理各类民商事合同纠纷案件的通用流程模板',
        category: 'contract',
        difficulty: 'high',
        estimatedDays: 60,
        author: '陈美玲律师',
        lastUpdated: '2024-01-10',
        usage: 89,
        icon: 'el-icon-document',
        tags: ['合同纠纷', '民商事', '协商诉讼']
      },
      {
        id: 'labor_dispute_template',
        name: '劳动争议处理流程',
        description: '处理劳动合同、工资争议等案件的专业流程',
        category: 'labor',
        difficulty: 'medium',
        estimatedDays: 45,
        author: '刘建国律师',
        lastUpdated: '2024-01-08',
        usage: 134,
        icon: 'el-icon-user-solid',
        tags: ['劳动争议', '仲裁', '工资纠纷']
      },
      {
        id: 'criminal_defense_template',
        name: '刑事辩护流程',
        description: '刑事案件辩护的完整程序流程模板',
        category: 'criminal',
        difficulty: 'high',
        estimatedDays: 90,
        author: '赵永强律师',
        lastUpdated: '2024-01-20',
        usage: 45,
        icon: 'el-icon-user',
        tags: ['刑事辩护', '法庭辩护', '会见']
      },
      {
        id: 'property_dispute_template',
        name: '房产纠纷处理流程',
        description: '房屋买卖、租赁、继承纠纷的处理流程',
        category: 'property',
        difficulty: 'medium',
        estimatedDays: 55,
        author: '孙丽娜律师',
        lastUpdated: '2024-01-12',
        usage: 67,
        icon: 'el-icon-house',
        tags: ['房产纠纷', '产权调查', '继承']
      },
      {
        id: 'intellectual_property_template',
        name: '知识产权纠纷流程',
        description: '专利、商标、著作权等知识产权案件处理流程',
        category: 'ip',
        difficulty: 'high',
        estimatedDays: 50,
        author: '孙律师',
        lastUpdated: '2024-01-18',
        usage: 28,
        icon: 'el-icon-cpu',
        tags: ['知识产权', '专利', '商标']
      },
      {
        id: 'divorce_mediation_template',
        name: '离婚调解流程',
        description: '婚姻家庭纠纷案件的调解和诉讼流程',
        category: 'family',
        difficulty: 'medium',
        estimatedDays: 40,
        author: '李律师',
        lastUpdated: '2024-01-16',
        usage: 72,
        icon: 'el-icon-female',
        tags: ['婚姻家庭', '离婚', '财产分割']
      },
      {
        id: 'corporate_legal_template',
        name: '企业法律顾问流程',
        description: '企业日常法律事务处理和风险防控流程',
        category: 'corporate',
        difficulty: 'medium',
        estimatedDays: 30,
        author: '周律师',
        lastUpdated: '2024-01-14',
        usage: 95,
        icon: 'el-icon-office-building',
        tags: ['企业法务', '合规', '风险防控']
      }
    ])

    // 流程管理数据
    const processCategories = ref([
      {
        id: 'traffic_accident',
        name: '交通事故处理流程',
        description: '适用于交通事故人身损害赔偿和财产损失处理',
        status: 'active',
        version: '2.1',
        lastUpdated: '2024-01-15',
        usage: 156,
        avgDuration: 35,
        nodes: [
          {
            id: 'ta_start',
            name: '案件接收',
            type: 'start',
            executor: '前台接待',
            executorRole: 'receptionist',
            estimatedDays: 1,
            position: { x: 100, y: 150 },
            description: '客户来访或电话咨询，接收案件基本信息',
            requiredDocuments: ['身份证', '事故认定书', '医疗费票据'],
            notifications: ['client', 'case_manager'],
            conditions: []
          },
          {
            id: 'ta_assign',
            name: '律师分配',
            type: 'process',
            executor: '案件经理',
            executorRole: 'case_manager',
            estimatedDays: 1,
            position: { x: 300, y: 150 },
            description: '根据案件复杂程度和律师专业领域分配主办律师',
            requiredDocuments: [],
            notifications: ['primary_lawyer', 'client'],
            conditions: [
              { field: 'case_complexity', operator: 'equals', value: 'simple', target: 'ta_evidence_simple' },
              { field: 'case_complexity', operator: 'equals', value: 'complex', target: 'ta_evidence_complex' }
            ]
          },
          {
            id: 'ta_evidence_simple',
            name: '简单证据收集',
            type: 'process',
            executor: '实习律师',
            executorRole: 'paralegal',
            estimatedDays: 3,
            position: { x: 500, y: 100 },
            description: '收集基础证据材料，包括现场照片、证人证言等',
            requiredDocuments: ['现场照片', '证人证言', '车辆损失评估'],
            notifications: ['primary_lawyer'],
            conditions: []
          },
          {
            id: 'ta_evidence_complex',
            name: '复杂证据收集',
            type: 'process',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 7,
            position: { x: 500, y: 200 },
            description: '深度调查取证，包括技术鉴定、专家意见等',
            requiredDocuments: ['技术鉴定报告', '专家意见书', '监控录像'],
            notifications: ['case_manager'],
            conditions: []
          },
          {
            id: 'ta_liability',
            name: '责任认定分析',
            type: 'decision',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 2,
            position: { x: 700, y: 150 },
            description: '分析责任比例，确定赔偿策略',
            requiredDocuments: ['责任分析报告'],
            notifications: ['client'],
            conditions: [
              { field: 'liability_clear', operator: 'equals', value: 'yes', target: 'ta_negotiation' },
              { field: 'liability_clear', operator: 'equals', value: 'no', target: 'ta_mediation' }
            ]
          },
          {
            id: 'ta_negotiation',
            name: '保险协商',
            type: 'process',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 10,
            position: { x: 900, y: 100 },
            description: '与保险公司协商赔偿金额和方案',
            requiredDocuments: ['协商记录', '赔偿计算书'],
            notifications: ['client', 'case_manager'],
            conditions: []
          },
          {
            id: 'ta_mediation',
            name: '调解程序',
            type: 'process',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 15,
            position: { x: 900, y: 200 },
            description: '申请交警或法院调解',
            requiredDocuments: ['调解申请书', '调解协议'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'ta_settlement',
            name: '结案处理',
            type: 'end',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 2,
            position: { x: 1100, y: 150 },
            description: '完成赔偿款支付，归档案件材料',
            requiredDocuments: ['赔偿协议', '收款凭证', '案件归档清单'],
            notifications: ['client', 'case_manager', 'finance'],
            conditions: []
          }
        ],
        connections: [
          { id: 'c1', from: 'ta_start', to: 'ta_assign', label: '' },
          { id: 'c2', from: 'ta_assign', to: 'ta_evidence_simple', label: '简单案件' },
          { id: 'c3', from: 'ta_assign', to: 'ta_evidence_complex', label: '复杂案件' },
          { id: 'c4', from: 'ta_evidence_simple', to: 'ta_liability', label: '' },
          { id: 'c5', from: 'ta_evidence_complex', to: 'ta_liability', label: '' },
          { id: 'c6', from: 'ta_liability', to: 'ta_negotiation', label: '责任明确' },
          { id: 'c7', from: 'ta_liability', to: 'ta_mediation', label: '需要调解' },
          { id: 'c8', from: 'ta_negotiation', to: 'ta_settlement', label: '' },
          { id: 'c9', from: 'ta_mediation', to: 'ta_settlement', label: '' }
        ]
      },
      {
        id: 'contract_dispute',
        name: '合同纠纷处理流程',
        description: '适用于各类民商事合同纠纷案件',
        status: 'active',
        version: '1.8',
        lastUpdated: '2024-01-10',
        usage: 89,
        avgDuration: 60,
        nodes: [
          {
            id: 'cd_start',
            name: '咨询接待',
            type: 'start',
            executor: '咨询律师',
            executorRole: 'consultant',
            estimatedDays: 1,
            position: { x: 100, y: 150 },
            description: '初步了解合同纠纷情况，评估案件可行性',
            requiredDocuments: ['合同原件', '履行证据', '违约证据'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'cd_review',
            name: '合同审查',
            type: 'process',
            executor: '专业律师',
            executorRole: 'specialist_lawyer',
            estimatedDays: 3,
            position: { x: 300, y: 150 },
            description: '详细审查合同条款，分析法律风险',
            requiredDocuments: ['合同分析报告', '风险评估报告'],
            notifications: ['client', 'case_manager'],
            conditions: []
          },
          {
            id: 'cd_strategy',
            name: '诉讼策略制定',
            type: 'decision',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 2,
            position: { x: 500, y: 150 },
            description: '制定诉讼或非诉讼解决方案',
            requiredDocuments: ['策略方案'],
            notifications: ['client'],
            conditions: [
              { field: 'resolution_type', operator: 'equals', value: 'litigation', target: 'cd_filing' },
              { field: 'resolution_type', operator: 'equals', value: 'negotiation', target: 'cd_negotiate' }
            ]
          },
          {
            id: 'cd_negotiate',
            name: '协商谈判',
            type: 'process',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 15,
            position: { x: 700, y: 100 },
            description: '与对方进行协商谈判',
            requiredDocuments: ['谈判记录', '和解协议草案'],
            notifications: ['client'],
            conditions: [
              { field: 'negotiation_success', operator: 'equals', value: 'yes', target: 'cd_settlement' },
              { field: 'negotiation_success', operator: 'equals', value: 'no', target: 'cd_filing' }
            ]
          },
          {
            id: 'cd_filing',
            name: '起诉立案',
            type: 'process',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 5,
            position: { x: 700, y: 200 },
            description: '准备起诉材料，向法院提起诉讼',
            requiredDocuments: ['起诉状', '证据清单', '诉讼费缴费单'],
            notifications: ['client', 'case_manager'],
            conditions: []
          },
          {
            id: 'cd_trial',
            name: '庭审参加',
            type: 'process',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 30,
            position: { x: 900, y: 200 },
            description: '参加法庭审理，进行法庭辩论',
            requiredDocuments: ['庭审笔录', '代理词'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'cd_settlement',
            name: '和解结案',
            type: 'end',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 3,
            position: { x: 900, y: 100 },
            description: '签署和解协议，完成案件处理',
            requiredDocuments: ['和解协议', '履行凭证'],
            notifications: ['client', 'case_manager'],
            conditions: []
          },
          {
            id: 'cd_judgment',
            name: '判决执行',
            type: 'end',
            executor: '主办律师',
            executorRole: 'primary_lawyer',
            estimatedDays: 7,
            position: { x: 1100, y: 200 },
            description: '协助客户执行法院判决',
            requiredDocuments: ['判决书', '执行申请书'],
            notifications: ['client', 'case_manager'],
            conditions: []
          }
        ],
        connections: [
          { id: 'cc1', from: 'cd_start', to: 'cd_review', label: '' },
          { id: 'cc2', from: 'cd_review', to: 'cd_strategy', label: '' },
          { id: 'cc3', from: 'cd_strategy', to: 'cd_negotiate', label: '协商解决' },
          { id: 'cc4', from: 'cd_strategy', to: 'cd_filing', label: '诉讼解决' },
          { id: 'cc5', from: 'cd_negotiate', to: 'cd_settlement', label: '协商成功' },
          { id: 'cc6', from: 'cd_negotiate', to: 'cd_filing', label: '协商失败' },
          { id: 'cc7', from: 'cd_filing', to: 'cd_trial', label: '' },
          { id: 'cc8', from: 'cd_trial', to: 'cd_judgment', label: '' }
        ]
      },
      {
        id: 'labor_dispute',
        name: '劳动争议处理流程',
        description: '处理劳动合同、工资、工伤等争议案件',
        status: 'active',
        version: '2.0',
        lastUpdated: '2024-01-08',
        usage: 234,
        avgDuration: 45,
        nodes: [
          {
            id: 'ld_start',
            name: '劳动咨询',
            type: 'start',
            executor: '劳动法律师',
            executorRole: 'labor_lawyer',
            estimatedDays: 1,
            position: { x: 100, y: 150 },
            description: '了解劳动争议具体情况，评估维权可能性',
            requiredDocuments: ['劳动合同', '工资条', '考勤记录'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'ld_evidence',
            name: '证据收集',
            type: 'process',
            executor: '劳动法律师',
            executorRole: 'labor_lawyer',
            estimatedDays: 5,
            position: { x: 300, y: 150 },
            description: '收集劳动关系证明、违法证据等材料',
            requiredDocuments: ['社保记录', '银行流水', '录音录像'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'ld_arbitration',
            name: '仲裁申请',
            type: 'process',
            executor: '劳动法律师',
            executorRole: 'labor_lawyer',
            estimatedDays: 3,
            position: { x: 500, y: 150 },
            description: '向劳动仲裁委员会提交仲裁申请',
            requiredDocuments: ['仲裁申请书', '证据材料'],
            notifications: ['client', 'case_manager'],
            conditions: []
          },
          {
            id: 'ld_hearing',
            name: '仲裁庭审',
            type: 'process',
            executor: '劳动法律师',
            executorRole: 'labor_lawyer',
            estimatedDays: 15,
            position: { x: 700, y: 150 },
            description: '参加劳动仲裁庭审，进行事实举证和法律论辩',
            requiredDocuments: ['庭审记录', '代理意见'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'ld_award_review',
            name: '裁决书审查',
            type: 'decision',
            executor: '劳动法律师',
            executorRole: 'labor_lawyer',
            estimatedDays: 2,
            position: { x: 900, y: 150 },
            description: '审查仲裁裁决书，决定是否上诉',
            requiredDocuments: ['仲裁裁决书'],
            notifications: ['client'],
            conditions: [
              { field: 'appeal_needed', operator: 'equals', value: 'yes', target: 'ld_lawsuit' },
              { field: 'appeal_needed', operator: 'equals', value: 'no', target: 'ld_enforcement' }
            ]
          },
          {
            id: 'ld_lawsuit',
            name: '法院诉讼',
            type: 'process',
            executor: '劳动法律师',
            executorRole: 'labor_lawyer',
            estimatedDays: 30,
            position: { x: 1100, y: 100 },
            description: '向人民法院提起诉讼',
            requiredDocuments: ['起诉状', '法院判决书'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'ld_enforcement',
            name: '强制执行',
            type: 'process',
            executor: '劳动法律师',
            executorRole: 'labor_lawyer',
            estimatedDays: 10,
            position: { x: 1100, y: 200 },
            description: '申请强制执行或协助履行',
            requiredDocuments: ['执行申请书', '履行凭证'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'ld_closure',
            name: '案件结案',
            type: 'end',
            executor: '劳动法律师',
            executorRole: 'labor_lawyer',
            estimatedDays: 2,
            position: { x: 1300, y: 150 },
            description: '完成权益维护，归档案件材料',
            requiredDocuments: ['结案报告', '归档清单'],
            notifications: ['client', 'case_manager'],
            conditions: []
          }
        ],
        connections: [
          { id: 'lc1', from: 'ld_start', to: 'ld_evidence', label: '' },
          { id: 'lc2', from: 'ld_evidence', to: 'ld_arbitration', label: '' },
          { id: 'lc3', from: 'ld_arbitration', to: 'ld_hearing', label: '' },
          { id: 'lc4', from: 'ld_hearing', to: 'ld_award_review', label: '' },
          { id: 'lc5', from: 'ld_award_review', to: 'ld_lawsuit', label: '不服裁决' },
          { id: 'lc6', from: 'ld_award_review', to: 'ld_enforcement', label: '接受裁决' },
          { id: 'lc7', from: 'ld_lawsuit', to: 'ld_closure', label: '' },
          { id: 'lc8', from: 'ld_enforcement', to: 'ld_closure', label: '' }
        ]
      },
      {
        id: 'property_dispute',
        name: '房产纠纷处理流程',
        description: '处理房屋买卖、租赁、继承等纠纷',
        status: 'active',
        version: '1.5',
        lastUpdated: '2024-01-12',
        usage: 67,
        avgDuration: 55,
        nodes: [
          {
            id: 'pd_start',
            name: '房产咨询',
            type: 'start',
            executor: '房产律师',
            executorRole: 'property_lawyer',
            estimatedDays: 1,
            position: { x: 100, y: 150 },
            description: '了解房产纠纷基本情况和客户诉求',
            requiredDocuments: ['房产证', '购房合同', '相关协议'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'pd_title_check',
            name: '产权调查',
            type: 'process',
            executor: '房产律师',
            executorRole: 'property_lawyer',
            estimatedDays: 3,
            position: { x: 300, y: 150 },
            description: '调查房产权属、抵押、查封等情况',
            requiredDocuments: ['产权调查报告', '不动产查询结果'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'pd_dispute_type',
            name: '纠纷类型判断',
            type: 'decision',
            executor: '房产律师',
            executorRole: 'property_lawyer',
            estimatedDays: 1,
            position: { x: 500, y: 150 },
            description: '判断纠纷性质，确定处理方案',
            requiredDocuments: ['案件分析报告'],
            notifications: ['client'],
            conditions: [
              { field: 'dispute_type', operator: 'equals', value: 'sale', target: 'pd_sale_dispute' },
              { field: 'dispute_type', operator: 'equals', value: 'lease', target: 'pd_lease_dispute' },
              { field: 'dispute_type', operator: 'equals', value: 'inheritance', target: 'pd_inheritance' }
            ]
          },
          {
            id: 'pd_sale_dispute',
            name: '买卖纠纷处理',
            type: 'process',
            executor: '房产律师',
            executorRole: 'property_lawyer',
            estimatedDays: 20,
            position: { x: 700, y: 80 },
            description: '处理房屋买卖合同纠纷',
            requiredDocuments: ['诉讼材料', '调解协议'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'pd_lease_dispute',
            name: '租赁纠纷处理',
            type: 'process',
            executor: '房产律师',
            executorRole: 'property_lawyer',
            estimatedDays: 15,
            position: { x: 700, y: 150 },
            description: '处理房屋租赁合同纠纷',
            requiredDocuments: ['租赁合同', '催收函'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'pd_inheritance',
            name: '继承纠纷处理',
            type: 'process',
            executor: '房产律师',
            executorRole: 'property_lawyer',
            estimatedDays: 25,
            position: { x: 700, y: 220 },
            description: '处理房产继承权纠纷',
            requiredDocuments: ['继承公证', '遗嘱认证'],
            notifications: ['client'],
            conditions: []
          },
          {
            id: 'pd_resolution',
            name: '纠纷解决',
            type: 'end',
            executor: '房产律师',
            executorRole: 'property_lawyer',
            estimatedDays: 5,
            position: { x: 900, y: 150 },
            description: '完成纠纷处理，办理相关手续',
            requiredDocuments: ['解决方案', '过户手续'],
            notifications: ['client', 'case_manager'],
            conditions: []
          }
        ],
        connections: [
          { id: 'pc1', from: 'pd_start', to: 'pd_title_check', label: '' },
          { id: 'pc2', from: 'pd_title_check', to: 'pd_dispute_type', label: '' },
          { id: 'pc3', from: 'pd_dispute_type', to: 'pd_sale_dispute', label: '买卖纠纷' },
          { id: 'pc4', from: 'pd_dispute_type', to: 'pd_lease_dispute', label: '租赁纠纷' },
          { id: 'pc5', from: 'pd_dispute_type', to: 'pd_inheritance', label: '继承纠纷' },
          { id: 'pc6', from: 'pd_sale_dispute', to: 'pd_resolution', label: '' },
          { id: 'pc7', from: 'pd_lease_dispute', to: 'pd_resolution', label: '' },
          { id: 'pc8', from: 'pd_inheritance', to: 'pd_resolution', label: '' }
        ]
      },
      {
        id: 'criminal_defense',
        name: '刑事辩护流程',
        description: '为刑事案件被告人提供法律辩护服务',
        status: 'active',
        version: '3.0',
        lastUpdated: '2024-01-20',
        usage: 45,
        avgDuration: 90,
        nodes: [
          {
            id: 'cr_start',
            name: '刑事咨询',
            type: 'start',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 1,
            position: { x: 100, y: 150 },
            description: '了解案件基本情况，评估辩护可能性',
            requiredDocuments: ['拘留通知书', '起诉书', '相关证据'],
            notifications: ['client', 'family'],
            conditions: []
          },
          {
            id: 'cr_meet_suspect',
            name: '会见嫌疑人',
            type: 'process',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 2,
            position: { x: 300, y: 150 },
            description: '到看守所会见嫌疑人，了解案情',
            requiredDocuments: ['会见笔录', '委托书'],
            notifications: ['family'],
            conditions: []
          },
          {
            id: 'cr_case_analysis',
            name: '案情分析',
            type: 'process',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 5,
            position: { x: 500, y: 150 },
            description: '深入分析案情，制定辩护策略',
            requiredDocuments: ['案件分析报告', '辩护思路'],
            notifications: ['family'],
            conditions: []
          },
          {
            id: 'cr_evidence_review',
            name: '证据审查',
            type: 'process',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 7,
            position: { x: 700, y: 150 },
            description: '申请查阅卷宗，审查控方证据',
            requiredDocuments: ['阅卷笔录', '证据分析'],
            notifications: ['family'],
            conditions: []
          },
          {
            id: 'cr_stage_decision',
            name: '程序阶段判断',
            type: 'decision',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 1,
            position: { x: 900, y: 150 },
            description: '判断案件所处阶段，确定辩护重点',
            requiredDocuments: [],
            notifications: [],
            conditions: [
              { field: 'case_stage', operator: 'equals', value: 'investigation', target: 'cr_investigation' },
              { field: 'case_stage', operator: 'equals', value: 'prosecution', target: 'cr_prosecution' },
              { field: 'case_stage', operator: 'equals', value: 'trial', target: 'cr_trial' }
            ]
          },
          {
            id: 'cr_investigation',
            name: '侦查阶段辩护',
            type: 'process',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 15,
            position: { x: 1100, y: 80 },
            description: '在侦查阶段提供法律援助',
            requiredDocuments: ['法律意见书', '取保申请'],
            notifications: ['family'],
            conditions: []
          },
          {
            id: 'cr_prosecution',
            name: '审查起诉辩护',
            type: 'process',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 10,
            position: { x: 1100, y: 150 },
            description: '在审查起诉阶段进行辩护',
            requiredDocuments: ['辩护意见', '不起诉申请'],
            notifications: ['family'],
            conditions: []
          },
          {
            id: 'cr_trial',
            name: '法庭辩护',
            type: 'process',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 20,
            position: { x: 1100, y: 220 },
            description: '参加法庭审理，进行辩护',
            requiredDocuments: ['辩护词', '庭审记录'],
            notifications: ['family'],
            conditions: []
          },
          {
            id: 'cr_appeal_review',
            name: '上诉评估',
            type: 'decision',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 3,
            position: { x: 1300, y: 150 },
            description: '评估是否需要上诉',
            requiredDocuments: ['判决书分析'],
            notifications: ['family'],
            conditions: [
              { field: 'appeal_needed', operator: 'equals', value: 'yes', target: 'cr_appeal' },
              { field: 'appeal_needed', operator: 'equals', value: 'no', target: 'cr_closure' }
            ]
          },
          {
            id: 'cr_appeal',
            name: '上诉程序',
            type: 'process',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 30,
            position: { x: 1500, y: 100 },
            description: '提起上诉，进行二审辩护',
            requiredDocuments: ['上诉状', '二审辩护词'],
            notifications: ['family'],
            conditions: []
          },
          {
            id: 'cr_closure',
            name: '案件结束',
            type: 'end',
            executor: '刑辩律师',
            executorRole: 'criminal_lawyer',
            estimatedDays: 2,
            position: { x: 1500, y: 200 },
            description: '完成辩护工作，归档案件',
            requiredDocuments: ['结案报告', '归档材料'],
            notifications: ['family', 'case_manager'],
            conditions: []
          }
        ],
        connections: [
          { id: 'crc1', from: 'cr_start', to: 'cr_meet_suspect', label: '' },
          { id: 'crc2', from: 'cr_meet_suspect', to: 'cr_case_analysis', label: '' },
          { id: 'crc3', from: 'cr_case_analysis', to: 'cr_evidence_review', label: '' },
          { id: 'crc4', from: 'cr_evidence_review', to: 'cr_stage_decision', label: '' },
          { id: 'crc5', from: 'cr_stage_decision', to: 'cr_investigation', label: '侦查阶段' },
          { id: 'crc6', from: 'cr_stage_decision', to: 'cr_prosecution', label: '起诉阶段' },
          { id: 'crc7', from: 'cr_stage_decision', to: 'cr_trial', label: '审判阶段' },
          { id: 'crc8', from: 'cr_investigation', to: 'cr_appeal_review', label: '' },
          { id: 'crc9', from: 'cr_prosecution', to: 'cr_appeal_review', label: '' },
          { id: 'crc10', from: 'cr_trial', to: 'cr_appeal_review', label: '' },
          { id: 'crc11', from: 'cr_appeal_review', to: 'cr_appeal', label: '提起上诉' },
          { id: 'crc12', from: 'cr_appeal_review', to: 'cr_closure', label: '不上诉' },
          { id: 'crc13', from: 'cr_appeal', to: 'cr_closure', label: '' }
        ]
      }
    ])

    // 期限管理数据
    const deadlineRules = ref([
      {
        id: 1,
        processName: '交通事故处理流程',
        processType: 'traffic_accident',
        deadlineRequirement: 35,
        reminderTime: 5,
        reminderEnabled: true,
        escalationEnabled: true,
        urgency: 'high',
        status: 'active',
        applicableRegions: ['全国'],
        createdBy: '张律师',
        lastModified: '2024-01-15',
        description: '交通事故案件处理的标准期限要求，确保客户权益及时维护'
      },
      {
        id: 2,
        processName: '合同纠纷处理流程',
        processType: 'contract_dispute',
        deadlineRequirement: 60,
        reminderTime: 7,
        reminderEnabled: true,
        escalationEnabled: true,
        urgency: 'normal',
        status: 'active',
        applicableRegions: ['全国'],
        createdBy: '李律师',
        lastModified: '2024-01-10',
        description: '合同纠纷案件的期限管理，包含协商和诉讼阶段'
      },
      {
        id: 3,
        processName: '劳动争议处理流程',
        processType: 'labor_dispute',
        deadlineRequirement: 45,
        reminderTime: 5,
        reminderEnabled: true,
        escalationEnabled: true,
        urgency: 'high',
        status: 'active',
        applicableRegions: ['全国'],
        createdBy: '王律师',
        lastModified: '2024-01-08',
        description: '劳动争议案件处理期限，考虑仲裁和诉讼时效要求'
      },
      {
        id: 4,
        processName: '房产纠纷处理流程',
        processType: 'property_dispute',
        deadlineRequirement: 55,
        reminderTime: 7,
        reminderEnabled: false,
        escalationEnabled: false,
        urgency: 'normal',
        status: 'active',
        applicableRegions: ['上海', '北京', '深圳'],
        createdBy: '陈律师',
        lastModified: '2024-01-12',
        description: '房产纠纷案件处理期限，包含产权调查和诉讼程序'
      },
      {
        id: 5,
        processName: '刑事辩护流程',
        processType: 'criminal_defense',
        deadlineRequirement: 90,
        reminderTime: 10,
        reminderEnabled: true,
        escalationEnabled: true,
        urgency: 'urgent',
        status: 'active',
        applicableRegions: ['全国'],
        createdBy: '赵律师',
        lastModified: '2024-01-20',
        description: '刑事案件辩护期限管理，严格按照法定程序时限执行'
      },
      {
        id: 6,
        processName: '知识产权纠纷流程',
        processType: 'ip_dispute',
        deadlineRequirement: 40,
        reminderTime: 5,
        reminderEnabled: true,
        escalationEnabled: true,
        urgency: 'high',
        status: 'draft',
        applicableRegions: ['北京', '上海', '广州', '深圳'],
        createdBy: '孙律师',
        lastModified: '2024-01-18',
        description: '知识产权案件处理期限，考虑专利、商标等不同类型'
      }
    ])

    const deadlineStats = ref({
      overdue: 8,
      approaching: 23,
      onTime: 445,
      avgDays: 42.3,
      totalCases: 476,
      overdueRate: '1.7%',
      onTimeRate: '93.5%',
      weeklyTrend: [
        { week: '第1周', overdue: 2, approaching: 18, onTime: 156 },
        { week: '第2周', overdue: 3, approaching: 21, onTime: 134 },
        { week: '第3周', overdue: 1, approaching: 19, onTime: 167 },
        { week: '第4周', overdue: 2, approaching: 23, onTime: 155 }
      ],
      byProcessType: [
        { type: '交通事故', total: 156, overdue: 3, onTimeRate: '98.1%' },
        { type: '合同纠纷', total: 89, overdue: 2, onTimeRate: '97.8%' },
        { type: '劳动争议', total: 134, overdue: 2, onTimeRate: '98.5%' },
        { type: '房产纠纷', total: 67, overdue: 1, onTimeRate: '98.5%' },
        { type: '刑事辩护', total: 30, overdue: 0, onTimeRate: '100%' }
      ]
    })

    // 通知管理数据
    const selectedNodes = ref([])
    const selectedMethods = ref([])
    const activeTemplate = ref('default')

    const businessNodes = ref([
      {
        id: 'deadline_reminder',
        name: '期限提醒',
        icon: 'el-icon-alarm-clock',
        events: ['期限临近', '期限到达', '超期预警'],
        description: '各类案件期限提醒和超期预警通知'
      },
      {
        id: 'traffic_receive',
        name: '交通事故接收',
        icon: 'el-icon-document-add',
        events: ['案件创建', '律师分配', '客户确认'],
        description: '交通事故案件的初始接收和分配流程'
      },
      {
        id: 'evidence_collect',
        name: '证据收集',
        icon: 'el-icon-view',
        events: ['开始收集', '收集完成', '补充材料'],
        description: '收集事故现场、医疗、保险等相关证据'
      },
      {
        id: 'liability_analysis',
        name: '责任认定',
        icon: 'el-icon-data-analysis',
        events: ['分析开始', '认定完成', '异议处理'],
        description: '分析事故责任比例和法律依据'
      },
      {
        id: 'insurance_nego',
        name: '保险协商',
        icon: 'el-icon-chat-dot-round',
        events: ['协商开始', '方案提交', '协商成功', '协商失败'],
        description: '与保险公司进行赔偿金额协商'
      },
      {
        id: 'court_process',
        name: '法庭程序',
        icon: 'el-icon-office-building',
        events: ['起诉立案', '庭审安排', '庭审完成', '判决结果'],
        description: '诉讼程序的各个关键节点'
      },
      {
        id: 'settlement',
        name: '结案处理',
        icon: 'el-icon-document-checked',
        events: ['和解达成', '款项到账', '案件归档'],
        description: '案件最终解决和结案归档'
      },
      {
        id: 'contract_review',
        name: '合同审查',
        icon: 'el-icon-document',
        events: ['审查开始', '风险识别', '审查完成'],
        description: '合同条款和法律风险的详细审查'
      },
      {
        id: 'labor_arbitration',
        name: '劳动仲裁',
        icon: 'el-icon-scale',
        events: ['申请提交', '庭审参加', '裁决结果'],
        description: '劳动争议仲裁程序的关键环节'
      },
      {
        id: 'property_investigation',
        name: '产权调查',
        icon: 'el-icon-search',
        events: ['调查开始', '权属确认', '调查完成'],
        description: '房产权属、抵押、查封等情况调查'
      },
      {
        id: 'criminal_defense',
        name: '刑事辩护',
        icon: 'el-icon-user',
        events: ['会见嫌疑人', '阅卷分析', '庭审辩护', '判决上诉'],
        description: '刑事案件辩护的各个程序阶段'
      }
    ])

    const recipientGroups = ref([
      {
        id: 'admin',
        name: '管理员组',
        selected: false,
        selectedMembers: [],
        description: '系统管理员和业务管理员',
        members: [
          { id: 'u1', name: '张晓明', role: '系统管理员', email: 'zhang.xiaoming@law.com', phone: '13800138001' },
          { id: 'u2', name: '李慧敏', role: '业务管理员', email: 'li.huimin@law.com', phone: '13800138002' }
        ]
      },
      {
        id: 'lawyers',
        name: '律师团队',
        selected: false,
        selectedMembers: [],
        description: '执业律师和法律顾问',
        members: [
          { id: 'u3', name: '王德华', role: '主任律师', email: 'wang.dehua@law.com', phone: '13800138003', speciality: '交通事故' },
          { id: 'u4', name: '陈美玲', role: '高级律师', email: 'chen.meiling@law.com', phone: '13800138004', speciality: '合同纠纷' },
          { id: 'u5', name: '刘建国', role: '律师', email: 'liu.jianguo@law.com', phone: '13800138005', speciality: '劳动争议' },
          { id: 'u6', name: '孙丽娜', role: '律师', email: 'sun.lina@law.com', phone: '13800138006', speciality: '房产纠纷' },
          { id: 'u7', name: '赵永强', role: '刑辩律师', email: 'zhao.yongqiang@law.com', phone: '13800138007', speciality: '刑事辩护' }
        ]
      },
      {
        id: 'paralegals',
        name: '助理团队',
        selected: false,
        selectedMembers: [],
        description: '律师助理和实习律师',
        members: [
          { id: 'u8', name: '周文静', role: '高级助理', email: 'zhou.wenjing@law.com', phone: '13800138008' },
          { id: 'u9', name: '吴志强', role: '律师助理', email: 'wu.zhiqiang@law.com', phone: '13800138009' },
          { id: 'u10', name: '郑雅婷', role: '实习律师', email: 'zheng.yating@law.com', phone: '13800138010' }
        ]
      },
      {
        id: 'clients',
        name: '客户组',
        selected: false,
        selectedMembers: [],
        description: '案件当事人和相关人员',
        members: [
          { id: 'c1', name: '当事人', role: '主要当事人', description: '案件的直接当事人' },
          { id: 'c2', name: '代理人', role: '法定代理人', description: '委托代理人或法定代理人' },
          { id: 'c3', name: '家属', role: '家属联系人', description: '当事人家属或紧急联系人' }
        ]
      },
      {
        id: 'support',
        name: '支持团队',
        selected: false,
        selectedMembers: [],
        description: '后勤支持和专业服务人员',
        members: [
          { id: 's1', name: '财务部', role: '财务管理', email: 'finance@law.com', phone: '13800138011' },
          { id: 's2', name: '前台接待', role: '客户接待', email: 'reception@law.com', phone: '13800138012' },
          { id: 's3', name: '档案管理', role: '档案管理员', email: 'archive@law.com', phone: '13800138013' }
        ]
      }
    ])

    const notificationMethods = ref([
      {
        id: 'email',
        name: '邮件通知',
        description: '发送邮件到用户邮箱',
        icon: 'el-icon-message'
      },
      {
        id: 'sms',
        name: '短信通知',
        description: '发送短信到用户手机',
        icon: 'el-icon-phone'
      },
      {
        id: 'system',
        name: '系统通知',
        description: '系统内消息推送',
        icon: 'el-icon-bell'
      },
      {
        id: 'wechat',
        name: '微信通知',
        description: '企业微信群消息',
        icon: 'el-icon-chat-dot-round'
      }
    ])

    const messageTemplates = ref([
      {
        id: 'case_received',
        name: '案件接收模板',
        title: '【案件接收】{{案件类型}}案件已受理',
        content: '尊敬的{{当事人}}，您好！\n\n您委托的{{案件类型}}案件已成功受理，案件详情如下：\n案件编号：{{案件编号}}\n受理时间：{{时间}}\n主办律师：{{主办律师}}\n联系电话：{{律师电话}}\n\n我们将竭诚为您提供专业的法律服务，如有疑问请随时联系。\n\n{{律所名称}}\n{{时间}}',
        category: 'client_notification',
        variables: ['当事人', '案件类型', '案件编号', '时间', '主办律师', '律师电话', '律所名称']
      },
      {
        id: 'lawyer_assigned',
        name: '律师分配模板',
        title: '【案件分配】新案件分配通知',
        content: '{{律师姓名}}，您好！\n\n新案件已分配给您，请及时处理：\n案件编号：{{案件编号}}\n案件类型：{{案件类型}}\n当事人：{{当事人}}\n联系方式：{{当事人电话}}\n案件描述：{{案件描述}}\n分配时间：{{时间}}\n\n请在24小时内联系当事人并开始案件处理工作。',
        category: 'lawyer_notification',
        variables: ['律师姓名', '案件编号', '案件类型', '当事人', '当事人电话', '案件描述', '时间']
      },
      {
        id: 'deadline_alert',
        name: '期限提醒模板',
        title: '【期限提醒】案件{{案件编号}}即将到期',
        content: '{{责任人}}，您好！\n\n案件{{案件编号}}即将到期，请注意：\n当前环节：{{当前环节}}\n剩余时间：{{剩余天数}}天\n预计完成时间：{{预计完成时间}}\n\n如需延期或有特殊情况，请及时与案件管理员联系。',
        category: 'deadline_reminder',
        variables: ['责任人', '案件编号', '当前环节', '剩余天数', '预计完成时间']
      },
      {
        id: 'court_notice',
        name: '庭审通知模板',
        title: '【庭审通知】{{案件编号}}开庭提醒',
        content: '{{当事人}}，您好！\n\n您的案件{{案件编号}}已确定开庭时间：\n开庭时间：{{开庭时间}}\n法院地址：{{法院地址}}\n审判庭：{{审判庭}}\n主办律师：{{主办律师}}\n\n请您按时出庭，如有变动我们会及时通知您。\n\n注意事项：\n1. 请携带身份证件\n2. 提前30分钟到达法院\n3. 如有疑问请联系主办律师',
        category: 'court_notification',
        variables: ['当事人', '案件编号', '开庭时间', '法院地址', '审判庭', '主办律师']
      },
      {
        id: 'case_result',
        name: '案件结果模板',
        title: '【案件结果】{{案件编号}}处理结果通知',
        content: '{{当事人}}，您好！\n\n您委托的案件{{案件编号}}已处理完毕：\n处理结果：{{处理结果}}\n结案时间：{{结案时间}}\n主办律师：{{主办律师}}\n\n{{结果详情}}\n\n感谢您对我们的信任，如有后续问题请随时联系。',
        category: 'result_notification',
        variables: ['当事人', '案件编号', '处理结果', '结案时间', '主办律师', '结果详情']
      },
      {
        id: 'case_closed',
        name: '结案归档模板',
        title: '【结案归档】{{案件编号}}已完成归档',
        content: '{{当事人}}，您好！\n\n您的案件{{案件编号}}已完成归档：\n归档时间：{{归档时间}}\n案件状态：已结案\n档案编号：{{档案编号}}\n\n如需查阅案件档案或获取相关文件，请联系我们的档案管理部门。',
        category: 'archive_notification',
        variables: ['当事人', '案件编号', '归档时间', '档案编号']
      },
      {
        id: 'urgent_alert',
        name: '紧急提醒模板',
        title: '【紧急提醒】{{紧急事项}}',
        content: '紧急通知！\n\n{{紧急内容}}\n\n时间：{{时间}}\n负责人：{{负责人}}\n联系方式：{{联系方式}}\n\n请立即处理！',
        category: 'urgent_notification',
        variables: ['紧急事项', '紧急内容', '时间', '负责人', '联系方式']
      },
      {
        id: 'evidence_reminder',
        name: '证据提醒模板',
        title: '【证据收集】请配合提供相关材料',
        content: '{{当事人}}，您好！\n\n为了更好地处理您的案件{{案件编号}}，请您配合提供以下材料：\n\n{{所需材料清单}}\n\n请在{{截止时间}}前提交，可通过以下方式：\n1. 到所咨询室递交\n2. 邮寄至：{{律所地址}}\n3. 电子版发送至：{{邮箱地址}}\n\n如有疑问请联系：{{联系人}} {{联系电话}}',
        category: 'evidence_request',
        variables: ['当事人', '案件编号', '所需材料清单', '截止时间', '律所地址', '邮箱地址', '联系人', '联系电话']
      }
    ])

    const currentTemplate = computed(() => {
      return messageTemplates.value.find(t => t.id === activeTemplate.value) || messageTemplates.value[0]
    })

    // 编辑数据
    const editingNode = ref({})
    const editingDeadline = ref({})

    // 方法
    const switchModule = (moduleId) => {
      activeModule.value = moduleId
    }

    // 可视化流程设计器方法
    const addNode = (type) => {
      const node = {
        id: `node_${nodeIdCounter++}`,
        type,
        title: '',
        description: '',
        x: 100 + Math.random() * 200,
        y: 100 + Math.random() * 200,
        responsible: '',
        duration: '',
        condition: '',
        notifications: ['system']
      }
      workflowNodes.value.push(node)
      selectNode(node.id)
    }

    const selectNode = (nodeId) => {
      selectedNode.value = nodeId
      const node = workflowNodes.value.find(n => n.id === nodeId)
      if (node) {
        selectedNodeData.value = { ...node }
      }
    }

    const deselectNode = () => {
      selectedNode.value = null
      selectedNodeData.value = {}
    }

    const deselectAll = () => {
      selectedNode.value = null
      selectedConnection.value = null
      selectedNodeData.value = {}
    }

    const deleteNode = (nodeId) => {
      // 删除节点
      workflowNodes.value = workflowNodes.value.filter(n => n.id !== nodeId)
      // 删除相关连接
      connections.value = connections.value.filter(c => c.from !== nodeId && c.to !== nodeId)
      if (selectedNode.value === nodeId) {
        deselectNode()
      }
    }

    const updateNodeData = () => {
      const node = workflowNodes.value.find(n => n.id === selectedNode.value)
      if (node) {
        Object.assign(node, selectedNodeData.value)
        ElMessage.success('节点更新成功')
      }
    }

    const getNodeIcon = (type) => {
      const nodeType = nodeTypes.value.find(nt => nt.type === type)
      return nodeType ? nodeType.icon : 'el-icon-question'
    }

    const getNodeLabel = (type) => {
      const nodeType = nodeTypes.value.find(nt => nt.type === type)
      return nodeType ? nodeType.label : '未知'
    }

    const getResponsibleName = (responsible) => {
      const names = {
        primary_lawyer: '主办律师',
        assistant_lawyer: '协办律师',
        paralegal: '律师助理',
        customer_service: '客服专员',
        finance_staff: '财务专员'
      }
      return names[responsible] || responsible
    }

    const startNodeDrag = (event, node) => {
      draggedNode.value = node
      const rect = canvas.value.getBoundingClientRect()
      const startX = event.clientX - rect.left - node.x
      const startY = event.clientY - rect.top - node.y

      const onMouseMove = (e) => {
        node.x = e.clientX - rect.left - startX
        node.y = e.clientY - rect.top - startY
      }

      const onMouseUp = () => {
        document.removeEventListener('mousemove', onMouseMove)
        document.removeEventListener('mouseup', onMouseUp)
        draggedNode.value = null
      }

      document.addEventListener('mousemove', onMouseMove)
      document.addEventListener('mouseup', onMouseUp)
    }

    const startConnection = (nodeId, type) => {
      const node = workflowNodes.value.find(n => n.id === nodeId)
      if (!node) return

      isConnecting.value = true
      connectionStart.value = { nodeId, type }

      const onMouseMove = (e) => {
        const rect = canvas.value.getBoundingClientRect()
        tempConnection.value = {
          x1: node.x + 100,
          y1: node.y + 50,
          x2: e.clientX - rect.left,
          y2: e.clientY - rect.top
        }
      }

      const onMouseUp = () => {
        isConnecting.value = false
        tempConnection.value = null
        connectionStart.value = null
        document.removeEventListener('mousemove', onMouseMove)
        document.removeEventListener('mouseup', onMouseUp)
      }

      document.addEventListener('mousemove', onMouseMove)
      document.addEventListener('mouseup', onMouseUp)
    }

    const getConnectionPath = (connection) => {
      const fromNode = workflowNodes.value.find(n => n.id === connection.from)
      const toNode = workflowNodes.value.find(n => n.id === connection.to)
      
      if (!fromNode || !toNode) return ''

      const x1 = fromNode.x + 100
      const y1 = fromNode.y + 50
      const x2 = toNode.x
      const y2 = toNode.y + 50

      // 创建贝塞尔曲线路径
      const cx1 = x1 + (x2 - x1) * 0.5
      const cy1 = y1
      const cx2 = x1 + (x2 - x1) * 0.5
      const cy2 = y2

      return `M ${x1} ${y1} C ${cx1} ${cy1}, ${cx2} ${cy2}, ${x2} ${y2}`
    }

    const clearCanvas = () => {
      workflowNodes.value = []
      connections.value = []
      deselectAll()
      ElMessage.success('画布已清空')
    }

    const autoLayout = () => {
      // 简单的自动布局算法
      workflowNodes.value.forEach((node, index) => {
        node.x = 50 + (index * 150)
        node.y = 100 + (index % 2) * 100
      })
      ElMessage.success('自动布局完成')
    }

    const zoomIn = () => {
      zoomLevel.value = Math.min(zoomLevel.value + 0.1, 2)
    }

    const zoomOut = () => {
      zoomLevel.value = Math.max(zoomLevel.value - 0.1, 0.5)
    }

    const loadTemplate = () => {
      if (!selectedTemplate.value) {
        ElMessage.warning('请先选择模板')
        return
      }
      
      // 根据选择的模板加载对应的流程数据
      switch (selectedTemplate.value) {
        case 'traffic_accident_template':
          // 交通事故处理流程
          workflowNodes.value = [
            { id: 'node1', type: 'start', title: '案件接收', x: 50, y: 150, description: '接收交通事故案件，登记基本信息', responsible: 'receptionist', duration: '0.5天' },
            { id: 'node2', type: 'process', title: '初步调查', x: 200, y: 150, description: '收集现场照片、事故认定书等基础材料', responsible: 'paralegal', duration: '2-3天' },
            { id: 'node3', type: 'decision', title: '责任认定', x: 350, y: 150, description: '分析责任比例，确定赔偿方向', condition: '责任明确且证据充分', responsible: 'primary_lawyer' },
            { id: 'node4', type: 'process', title: '证据收集', x: 500, y: 80, description: '收集医疗记录、收入证明、维修发票等', responsible: 'paralegal', duration: '5-7天' },
            { id: 'node5', type: 'process', title: '损失评估', x: 650, y: 80, description: '计算医疗费、误工费、精神损失等', responsible: 'primary_lawyer', duration: '3-5天' },
            { id: 'node6', type: 'process', title: '协商谈判', x: 500, y: 220, description: '与保险公司或对方当事人协商赔偿', responsible: 'primary_lawyer', duration: '10-15天' },
            { id: 'node7', type: 'decision', title: '协商结果', x: 650, y: 220, description: '评估协商结果是否满意', condition: '赔偿金额合理', responsible: 'primary_lawyer' },
            { id: 'node8', type: 'process', title: '诉讼准备', x: 800, y: 280, description: '准备起诉材料，向法院提起诉讼', responsible: 'primary_lawyer', duration: '7-10天' },
            { id: 'node9', type: 'process', title: '和解协议', x: 800, y: 150, description: '签署和解协议，办理赔偿手续', responsible: 'primary_lawyer', duration: '2-3天' },
            { id: 'node10', type: 'end', title: '案件结案', x: 950, y: 150, description: '案件归档，客户回访' }
          ]
          
          connections.value = [
            { id: 'conn1', from: 'node1', to: 'node2', label: '立案' },
            { id: 'conn2', from: 'node2', to: 'node3', label: '调查完成' },
            { id: 'conn3', from: 'node3', to: 'node4', label: '责任明确' },
            { id: 'conn4', from: 'node3', to: 'node6', label: '责任争议' },
            { id: 'conn5', from: 'node4', to: 'node5', label: '证据充分' },
            { id: 'conn6', from: 'node5', to: 'node9', label: '直接和解' },
            { id: 'conn7', from: 'node6', to: 'node7', label: '协商完成' },
            { id: 'conn8', from: 'node7', to: 'node9', label: '协商成功' },
            { id: 'conn9', from: 'node7', to: 'node8', label: '协商失败' },
            { id: 'conn10', from: 'node8', to: 'node10', label: '诉讼结案' },
            { id: 'conn11', from: 'node9', to: 'node10', label: '和解完成' }
          ]
          break

        case 'contract_dispute_template':
          // 合同纠纷处理流程
          workflowNodes.value = [
            { id: 'node1', type: 'start', title: '案件受理', x: 50, y: 150, description: '接收合同纠纷案件，审查合同文本', responsible: 'receptionist', duration: '1天' },
            { id: 'node2', type: 'process', title: '合同分析', x: 200, y: 150, description: '分析合同条款，识别争议焦点', responsible: 'contract_lawyer', duration: '3-5天' },
            { id: 'node3', type: 'process', title: '证据梳理', x: 350, y: 150, description: '整理履行记录、往来函件等证据', responsible: 'paralegal', duration: '5-7天' },
            { id: 'node4', type: 'decision', title: '案件评估', x: 500, y: 150, description: '评估胜诉可能性和风险', condition: '证据充分，胜算较大', responsible: 'contract_lawyer' },
            { id: 'node5', type: 'process', title: '协商谈判', x: 650, y: 80, description: '与对方协商解决方案', responsible: 'contract_lawyer', duration: '10-15天' },
            { id: 'node6', type: 'process', title: '调解申请', x: 650, y: 220, description: '申请人民调解或商事调解', responsible: 'contract_lawyer', duration: '15-20天' },
            { id: 'node7', type: 'decision', title: '调解结果', x: 800, y: 150, description: '评估调解方案', condition: '调解方案可接受', responsible: 'contract_lawyer' },
            { id: 'node8', type: 'process', title: '诉讼程序', x: 950, y: 220, description: '向法院提起诉讼', responsible: 'contract_lawyer', duration: '60-90天' },
            { id: 'node9', type: 'process', title: '调解协议', x: 950, y: 80, description: '签署调解协议', responsible: 'contract_lawyer', duration: '2-3天' },
            { id: 'node10', type: 'end', title: '案件完结', x: 1100, y: 150, description: '案件归档，执行监督' }
          ]
          
          connections.value = [
            { id: 'conn1', from: 'node1', to: 'node2', label: '受理' },
            { id: 'conn2', from: 'node2', to: 'node3', label: '分析完成' },
            { id: 'conn3', from: 'node3', to: 'node4', label: '证据整理' },
            { id: 'conn4', from: 'node4', to: 'node5', label: '优势明显' },
            { id: 'conn5', from: 'node4', to: 'node6', label: '需要调解' },
            { id: 'conn6', from: 'node5', to: 'node9', label: '协商成功' },
            { id: 'conn7', from: 'node5', to: 'node6', label: '协商失败' },
            { id: 'conn8', from: 'node6', to: 'node7', label: '调解完成' },
            { id: 'conn9', from: 'node7', to: 'node9', label: '接受调解' },
            { id: 'conn10', from: 'node7', to: 'node8', label: '拒绝调解' },
            { id: 'conn11', from: 'node8', to: 'node10', label: '判决生效' },
            { id: 'conn12', from: 'node9', to: 'node10', label: '协议履行' }
          ]
          break

        case 'labor_dispute_template':
          // 劳动争议处理流程
          workflowNodes.value = [
            { id: 'node1', type: 'start', title: '争议受理', x: 50, y: 150, description: '接收劳动争议案件', responsible: 'receptionist', duration: '0.5天' },
            { id: 'node2', type: 'process', title: '材料审查', x: 200, y: 150, description: '审查劳动合同、工资条等材料', responsible: 'labor_lawyer', duration: '2-3天' },
            { id: 'node3', type: 'process', title: '证据收集', x: 350, y: 150, description: '收集考勤记录、工作邮件等证据', responsible: 'paralegal', duration: '5-7天' },
            { id: 'node4', type: 'decision', title: '争议性质', x: 500, y: 150, description: '判断争议类型和复杂程度', condition: '争议明确', responsible: 'labor_lawyer' },
            { id: 'node5', type: 'process', title: '劳动仲裁', x: 650, y: 80, description: '向劳动仲裁委申请仲裁', responsible: 'labor_lawyer', duration: '45天' },
            { id: 'node6', type: 'process', title: '协商调解', x: 650, y: 220, description: '与用人单位协商解决', responsible: 'labor_lawyer', duration: '10-15天' },
            { id: 'node7', type: 'decision', title: '仲裁结果', x: 800, y: 80, description: '仲裁裁决是否满意', condition: '裁决公正', responsible: 'labor_lawyer' },
            { id: 'node8', type: 'process', title: '法院诉讼', x: 950, y: 80, description: '对仲裁不服，提起诉讼', responsible: 'labor_lawyer', duration: '60天' },
            { id: 'node9', type: 'process', title: '执行程序', x: 950, y: 150, description: '申请强制执行', responsible: 'labor_lawyer', duration: '30天' },
            { id: 'node10', type: 'end', title: '争议解决', x: 1100, y: 150, description: '争议彻底解决' }
          ]
          
          connections.value = [
            { id: 'conn1', from: 'node1', to: 'node2', label: '立案' },
            { id: 'conn2', from: 'node2', to: 'node3', label: '审查通过' },
            { id: 'conn3', from: 'node3', to: 'node4', label: '证据完备' },
            { id: 'conn4', from: 'node4', to: 'node5', label: '申请仲裁' },
            { id: 'conn5', from: 'node4', to: 'node6', label: '尝试调解' },
            { id: 'conn6', from: 'node6', to: 'node10', label: '调解成功' },
            { id: 'conn7', from: 'node6', to: 'node5', label: '调解失败' },
            { id: 'conn8', from: 'node5', to: 'node7', label: '仲裁完成' },
            { id: 'conn9', from: 'node7', to: 'node9', label: '接受裁决' },
            { id: 'conn10', from: 'node7', to: 'node8', label: '不服裁决' },
            { id: 'conn11', from: 'node8', to: 'node9', label: '胜诉' },
            { id: 'conn12', from: 'node9', to: 'node10', label: '执行完毕' }
          ]
          break

        case 'criminal_defense_template':
          // 刑事辩护流程
          workflowNodes.value = [
            { id: 'node1', type: 'start', title: '案件委托', x: 50, y: 200, description: '接受刑事案件辩护委托', responsible: 'receptionist', duration: '1天' },
            { id: 'node2', type: 'process', title: '会见当事人', x: 200, y: 200, description: '前往看守所会见被告人', responsible: 'criminal_lawyer', duration: '1天' },
            { id: 'node3', type: 'process', title: '案卷研究', x: 350, y: 200, description: '研究起诉书和案卷材料', responsible: 'criminal_lawyer', duration: '5-7天' },
            { id: 'node4', type: 'process', title: '证据调查', x: 500, y: 200, description: '收集有利证据和证人证言', responsible: 'criminal_lawyer', duration: '10-15天' },
            { id: 'node5', type: 'decision', title: '辩护策略', x: 650, y: 200, description: '确定无罪或罪轻辩护策略', condition: '策略明确', responsible: 'criminal_lawyer' },
            { id: 'node6', type: 'process', title: '庭前准备', x: 800, y: 130, description: '准备辩护词和质证意见', responsible: 'criminal_lawyer', duration: '7-10天' },
            { id: 'node7', type: 'process', title: '申请取保', x: 800, y: 270, description: '符合条件的申请取保候审', responsible: 'criminal_lawyer', duration: '3-5天' },
            { id: 'node8', type: 'process', title: '法庭辩护', x: 950, y: 200, description: '出庭进行法庭辩护', responsible: 'criminal_lawyer', duration: '1-3天' },
            { id: 'node9', type: 'decision', title: '判决结果', x: 1100, y: 200, description: '分析一审判决结果', condition: '判决合理', responsible: 'criminal_lawyer' },
            { id: 'node10', type: 'process', title: '上诉程序', x: 1250, y: 270, description: '不服判决提起上诉', responsible: 'criminal_lawyer', duration: '30天' },
            { id: 'node11', type: 'process', title: '刑罚执行', x: 1250, y: 130, description: '协助办理刑罚执行手续', responsible: 'criminal_lawyer', duration: '5天' },
            { id: 'node12', type: 'end', title: '辩护结束', x: 1400, y: 200, description: '刑事辩护工作结束' }
          ]
          
          connections.value = [
            { id: 'conn1', from: 'node1', to: 'node2', label: '委托确认' },
            { id: 'conn2', from: 'node2', to: 'node3', label: '会见完成' },
            { id: 'conn3', from: 'node3', to: 'node4', label: '案情了解' },
            { id: 'conn4', from: 'node4', to: 'node5', label: '调查完成' },
            { id: 'conn5', from: 'node5', to: 'node6', label: '无罪辩护' },
            { id: 'conn6', from: 'node5', to: 'node7', label: '罪轻辩护' },
            { id: 'conn7', from: 'node6', to: 'node8', label: '准备就绪' },
            { id: 'conn8', from: 'node7', to: 'node8', label: '取保成功' },
            { id: 'conn9', from: 'node8', to: 'node9', label: '庭审结束' },
            { id: 'conn10', from: 'node9', to: 'node11', label: '接受判决' },
            { id: 'conn11', from: 'node9', to: 'node10', label: '提起上诉' },
            { id: 'conn12', from: 'node10', to: 'node12', label: '上诉完成' },
            { id: 'conn13', from: 'node11', to: 'node12', label: '执行完毕' }
          ]
          break

        case 'property_dispute_template':
          // 房产纠纷处理流程
          workflowNodes.value = [
            { id: 'node1', type: 'start', title: '纠纷受理', x: 50, y: 150, description: '接收房产纠纷案件', responsible: 'receptionist', duration: '1天' },
            { id: 'node2', type: 'process', title: '产权调查', x: 200, y: 150, description: '查询房产登记信息和权属状况', responsible: 'property_lawyer', duration: '3-5天' },
            { id: 'node3', type: 'process', title: '合同审查', x: 350, y: 150, description: '审查买卖合同、租赁合同等', responsible: 'property_lawyer', duration: '2-3天' },
            { id: 'node4', type: 'decision', title: '纠纷类型', x: 500, y: 150, description: '确定是买卖、租赁还是继承纠纷', condition: '类型明确', responsible: 'property_lawyer' },
            { id: 'node5', type: 'process', title: '权属确认', x: 650, y: 80, description: '确认房产真实权属关系', responsible: 'property_lawyer', duration: '7-10天' },
            { id: 'node6', type: 'process', title: '损失评估', x: 650, y: 220, description: '评估经济损失和违约责任', responsible: 'property_lawyer', duration: '5-7天' },
            { id: 'node7', type: 'process', title: '协商调解', x: 800, y: 150, description: '与各方协商解决方案', responsible: 'property_lawyer', duration: '15-20天' },
            { id: 'node8', type: 'decision', title: '调解结果', x: 950, y: 150, description: '调解是否成功', condition: '达成协议', responsible: 'property_lawyer' },
            { id: 'node9', type: 'process', title: '诉讼程序', x: 1100, y: 220, description: '向法院提起诉讼', responsible: 'property_lawyer', duration: '90-120天' },
            { id: 'node10', type: 'process', title: '协议执行', x: 1100, y: 80, description: '监督协议履行', responsible: 'property_lawyer', duration: '30天' },
            { id: 'node11', type: 'end', title: '纠纷解决', x: 1250, y: 150, description: '房产纠纷彻底解决' }
          ]
          
          connections.value = [
            { id: 'conn1', from: 'node1', to: 'node2', label: '立案' },
            { id: 'conn2', from: 'node2', to: 'node3', label: '调查完成' },
            { id: 'conn3', from: 'node3', to: 'node4', label: '审查完成' },
            { id: 'conn4', from: 'node4', to: 'node5', label: '权属争议' },
            { id: 'conn5', from: 'node4', to: 'node6', label: '损失争议' },
            { id: 'conn6', from: 'node5', to: 'node7', label: '权属清晰' },
            { id: 'conn7', from: 'node6', to: 'node7', label: '损失确定' },
            { id: 'conn8', from: 'node7', to: 'node8', label: '调解完成' },
            { id: 'conn9', from: 'node8', to: 'node10', label: '调解成功' },
            { id: 'conn10', from: 'node8', to: 'node9', label: '调解失败' },
            { id: 'conn11', from: 'node9', to: 'node11', label: '判决生效' },
            { id: 'conn12', from: 'node10', to: 'node11', label: '履行完毕' }
          ]
          break

        case 'intellectual_property_template':
          // 知识产权纠纷流程
          workflowNodes.value = [
            { id: 'node1', type: 'start', title: '案件受理', x: 50, y: 150, description: '接收知识产权纠纷案件', responsible: 'receptionist', duration: '1天' },
            { id: 'node2', type: 'process', title: '权利确认', x: 200, y: 150, description: '确认专利、商标或著作权的有效性', responsible: 'ip_lawyer', duration: '5-7天' },
            { id: 'node3', type: 'process', title: '侵权调查', x: 350, y: 150, description: '调查侵权行为和损失情况', responsible: 'ip_lawyer', duration: '10-15天' },
            { id: 'node4', type: 'decision', title: '侵权认定', x: 500, y: 150, description: '确定是否构成侵权', condition: '侵权事实清楚', responsible: 'ip_lawyer' },
            { id: 'node5', type: 'process', title: '证据保全', x: 650, y: 80, description: '申请证据保全和财产保全', responsible: 'ip_lawyer', duration: '3-5天' },
            { id: 'node6', type: 'process', title: '损失计算', x: 650, y: 220, description: '计算经济损失和合理费用', responsible: 'ip_lawyer', duration: '7-10天' },
            { id: 'node7', type: 'process', title: '和解谈判', x: 800, y: 150, description: '与侵权方协商解决', responsible: 'ip_lawyer', duration: '15-20天' },
            { id: 'node8', type: 'decision', title: '和解结果', x: 950, y: 150, description: '和解是否达成', condition: '赔偿合理', responsible: 'ip_lawyer' },
            { id: 'node9', type: 'process', title: '诉讼程序', x: 1100, y: 220, description: '向法院提起知识产权诉讼', responsible: 'ip_lawyer', duration: '120-180天' },
            { id: 'node10', type: 'process', title: '和解协议', x: 1100, y: 80, description: '签署和解协议', responsible: 'ip_lawyer', duration: '3天' },
            { id: 'node11', type: 'end', title: '案件结案', x: 1250, y: 150, description: '知识产权纠纷解决' }
          ]
          
          connections.value = [
            { id: 'conn1', from: 'node1', to: 'node2', label: '受理' },
            { id: 'conn2', from: 'node2', to: 'node3', label: '权利有效' },
            { id: 'conn3', from: 'node3', to: 'node4', label: '调查完成' },
            { id: 'conn4', from: 'node4', to: 'node5', label: '构成侵权' },
            { id: 'conn5', from: 'node4', to: 'node6', label: '需要赔偿' },
            { id: 'conn6', from: 'node5', to: 'node7', label: '证据固定' },
            { id: 'conn7', from: 'node6', to: 'node7', label: '损失确定' },
            { id: 'conn8', from: 'node7', to: 'node8', label: '谈判完成' },
            { id: 'conn9', from: 'node8', to: 'node10', label: '和解成功' },
            { id: 'conn10', from: 'node8', to: 'node9', label: '和解失败' },
            { id: 'conn11', from: 'node9', to: 'node11', label: '判决生效' },
            { id: 'conn12', from: 'node10', to: 'node11', label: '协议履行' }
          ]
          break

        case 'divorce_mediation_template':
          // 离婚调解流程
          workflowNodes.value = [
            { id: 'node1', type: 'start', title: '案件受理', x: 50, y: 150, description: '接收离婚案件委托', responsible: 'receptionist', duration: '1天' },
            { id: 'node2', type: 'process', title: '情况了解', x: 200, y: 150, description: '了解夫妻感情状况和争议焦点', responsible: 'family_lawyer', duration: '2-3天' },
            { id: 'node3', type: 'decision', title: '调解可能', x: 350, y: 150, description: '评估调解和好的可能性', condition: '有和好可能', responsible: 'family_lawyer' },
            { id: 'node4', type: 'process', title: '婚姻调解', x: 500, y: 80, description: '进行夫妻关系调解', responsible: 'family_lawyer', duration: '10-15天' },
            { id: 'node5', type: 'process', title: '财产调查', x: 500, y: 220, description: '调查夫妻共同财产状况', responsible: 'paralegal', duration: '7-10天' },
            { id: 'node6', type: 'decision', title: '调解结果', x: 650, y: 80, description: '夫妻是否和好', condition: '关系修复', responsible: 'family_lawyer' },
            { id: 'node7', type: 'process', title: '财产分割', x: 650, y: 220, description: '协商财产分割方案', responsible: 'family_lawyer', duration: '5-10天' },
            { id: 'node8', type: 'process', title: '子女抚养', x: 800, y: 220, description: '确定子女抚养和探视方案', responsible: 'family_lawyer', duration: '5-7天' },
            { id: 'node9', type: 'process', title: '离婚协议', x: 950, y: 220, description: '起草离婚协议书', responsible: 'family_lawyer', duration: '2-3天' },
            { id: 'node10', type: 'process', title: '诉讼离婚', x: 950, y: 280, description: '向法院提起离婚诉讼', responsible: 'family_lawyer', duration: '60-90天' },
            { id: 'node11', type: 'process', title: '和好协议', x: 800, y: 80, description: '签署夫妻和好协议', responsible: 'family_lawyer', duration: '1天' },
            { id: 'node12', type: 'end', title: '案件结案', x: 1100, y: 150, description: '婚姻纠纷处理完毕' }
          ]
          
          connections.value = [
            { id: 'conn1', from: 'node1', to: 'node2', label: '受理' },
            { id: 'conn2', from: 'node2', to: 'node3', label: '了解完成' },
            { id: 'conn3', from: 'node3', to: 'node4', label: '尝试调解' },
            { id: 'conn4', from: 'node3', to: 'node5', label: '坚决离婚' },
            { id: 'conn5', from: 'node4', to: 'node6', label: '调解完成' },
            { id: 'conn6', from: 'node6', to: 'node11', label: '和好成功' },
            { id: 'conn7', from: 'node6', to: 'node5', label: '调解失败' },
            { id: 'conn8', from: 'node5', to: 'node7', label: '财产清楚' },
            { id: 'conn9', from: 'node7', to: 'node8', label: '分割完成' },
            { id: 'conn10', from: 'node8', to: 'node9', label: '协商一致' },
            { id: 'conn11', from: 'node8', to: 'node10', label: '协商失败' },
            { id: 'conn12', from: 'node9', to: 'node12', label: '协议离婚' },
            { id: 'conn13', from: 'node10', to: 'node12', label: '判决离婚' },
            { id: 'conn14', from: 'node11', to: 'node12', label: '和好结案' }
          ]
          break

        case 'corporate_legal_template':
          // 企业法律顾问流程
          workflowNodes.value = [
            { id: 'node1', type: 'start', title: '顾问委托', x: 50, y: 150, description: '签署企业法律顾问合同', responsible: 'receptionist', duration: '1天' },
            { id: 'node2', type: 'process', title: '企业调研', x: 200, y: 150, description: '了解企业经营状况和法律需求', responsible: 'corporate_lawyer', duration: '5-7天' },
            { id: 'node3', type: 'process', title: '风险评估', x: 350, y: 150, description: '评估企业面临的法律风险', responsible: 'corporate_lawyer', duration: '7-10天' },
            { id: 'node4', type: 'process', title: '制度建设', x: 500, y: 80, description: '完善企业内部法律制度', responsible: 'corporate_lawyer', duration: '15-20天' },
            { id: 'node5', type: 'process', title: '合同审查', x: 500, y: 220, description: '审查企业对外签署的合同', responsible: 'corporate_lawyer', duration: '持续进行' },
            { id: 'node6', type: 'process', title: '培训指导', x: 650, y: 80, description: '对企业员工进行法律培训', responsible: 'corporate_lawyer', duration: '定期进行' },
            { id: 'node7', type: 'process', title: '争议处理', x: 650, y: 220, description: '处理企业涉及的法律争议', responsible: 'corporate_lawyer', duration: '按需处理' },
            { id: 'node8', type: 'process', title: '合规监督', x: 800, y: 150, description: '监督企业合规经营', responsible: 'corporate_lawyer', duration: '持续监督' },
            { id: 'node9', type: 'decision', title: '服务评估', x: 950, y: 150, description: '定期评估法律服务效果', condition: '服务满意', responsible: 'corporate_lawyer' },
            { id: 'node10', type: 'process', title: '服务优化', x: 1100, y: 220, description: '优化法律服务方案', responsible: 'corporate_lawyer', duration: '5-7天' },
            { id: 'node11', type: 'process', title: '续约服务', x: 1100, y: 80, description: '续签法律顾问合同', responsible: 'corporate_lawyer', duration: '2-3天' },
            { id: 'node12', type: 'end', title: '服务完成', x: 1250, y: 150, description: '法律顾问服务期满' }
          ]
          
          connections.value = [
            { id: 'conn1', from: 'node1', to: 'node2', label: '委托确认' },
            { id: 'conn2', from: 'node2', to: 'node3', label: '调研完成' },
            { id: 'conn3', from: 'node3', to: 'node4', label: '风险识别' },
            { id: 'conn4', from: 'node3', to: 'node5', label: '日常服务' },
            { id: 'conn5', from: 'node4', to: 'node6', label: '制度完善' },
            { id: 'conn6', from: 'node5', to: 'node7', label: '发现争议' },
            { id: 'conn7', from: 'node6', to: 'node8', label: '培训完成' },
            { id: 'conn8', from: 'node7', to: 'node8', label: '争议解决' },
            { id: 'conn9', from: 'node8', to: 'node9', label: '定期评估' },
            { id: 'conn10', from: 'node9', to: 'node11', label: '服务满意' },
            { id: 'conn11', from: 'node9', to: 'node10', label: '需要改进' },
            { id: 'conn12', from: 'node10', to: 'node11', label: '优化完成' },
            { id: 'conn13', from: 'node11', to: 'node12', label: '合同到期' }
          ]
          break

        default:
          ElMessage.warning('未找到对应的模板')
          return
      }
      
      // 重置选择状态
      selectedNode.value = null
      selectedConnection.value = null
      selectedNodeData.value = {}
      
      const templateName = processTemplates.value.find(t => t.id === selectedTemplate.value)?.name
      ElMessage.success(`${templateName} 模板加载成功！`)
    }

    const saveWorkflow = () => {
      if (workflowNodes.value.length === 0) {
        ElMessage.warning('请先添加流程节点')
        return
      }
      
      // 保存工作流程逻辑
      ElMessage.success('工作流程保存成功')
    }

    const previewWorkflow = () => {
      if (workflowNodes.value.length === 0) {
        ElMessage.warning('暂无流程可预览')
        return
      }
      
      // 预览工作流程逻辑
      ElMessage.info('预览功能开发中...')
    }

    const addDeadlineRule = () => {
      editingDeadline.value = {
        processName: '',
        deadlineRequirement: 7,
        reminderTime: 1,
        reminderEnabled: true,
        escalationEnabled: false,
        urgency: 'normal'
      }
      deadlineDialogVisible.value = true
    }

    const editDeadlineRule = (rule) => {
      editingDeadline.value = { ...rule }
      deadlineDialogVisible.value = true
    }

    const saveDeadlineRule = () => {
      deadlineDialogVisible.value = false
      ElMessage.success('期限规则保存成功')
    }

    const deleteDeadlineRule = async (rule) => {
      try {
        await ElMessageBox.confirm('确定要删除这个期限规则吗？', '确认删除', {
          type: 'warning'
        })
        const index = deadlineRules.value.findIndex(r => r.id === rule.id)
        if (index > -1) {
          deadlineRules.value.splice(index, 1)
          ElMessage.success('删除成功')
        }
      } catch {
        // 用户取消删除
      }
    }

    const testReminder = (rule) => {
      ElMessage.success(`测试提醒发送成功：${rule.processName}`)
    }

    const configureNotification = (rule) => {
      // 跳转到消息通知管理，并高亮相关规则
      activeModule.value = 'notification'
      ElMessage.info(`已跳转到消息通知管理，请配置 ${rule.processName} 的通知方式`)
    }

    const updateEscalation = (rule) => {
      ElMessage.success(`升级设置已${rule.escalationEnabled ? '启用' : '禁用'}`)
    }

    const batchSetDeadlines = () => {
      ElMessage.success('批量设置功能开发中...')
    }

    const viewDeadlineStats = () => {
      ElMessage.success('期限统计功能开发中...')
    }

    const toggleNodeSelection = (nodeId) => {
      const index = selectedNodes.value.indexOf(nodeId)
      if (index > -1) {
        selectedNodes.value.splice(index, 1)
      } else {
        selectedNodes.value.push(nodeId)
      }
    }

    const toggleMethodSelection = (methodId) => {
      const index = selectedMethods.value.indexOf(methodId)
      if (index > -1) {
        selectedMethods.value.splice(index, 1)
      } else {
        selectedMethods.value.push(methodId)
      }
    }

    const toggleRecipientGroup = (group) => {
      if (group.selected) {
        group.selectedMembers = group.members.map(m => m.id)
      } else {
        group.selectedMembers = []
      }
    }

    const switchTemplate = (templateId) => {
      activeTemplate.value = templateId
    }

    const addTemplate = () => {
      const newTemplate = {
        id: `template_${Date.now()}`,
        name: '新模板',
        title: '',
        content: ''
      }
      messageTemplates.value.push(newTemplate)
      activeTemplate.value = newTemplate.id
    }

    const saveNotificationConfig = () => {
      ElMessage.success('通知配置保存成功')
    }

    const previewNotification = () => {
      ElMessage.success('预览通知功能开发中...')
    }

    const resetConfig = () => {
      selectedNodes.value = []
      selectedMethods.value = []
      recipientGroups.value.forEach(group => {
        group.selected = false
        group.selectedMembers = []
      })
      ElMessage.success('配置已重置')
    }

    const addNotificationRule = () => {
      ElMessage.success('新增通知规则功能开发中...')
    }

    const manageTemplates = () => {
      ElMessage.success('模板管理功能开发中...')
    }

    const testNotification = () => {
      ElMessage.success('测试通知功能开发中...')
    }

    // 辅助方法
    const getNodeTypeName = (type) => {
      const typeNames = {
        start: '开始',
        process: '处理',
        approval: '审批',
        decision: '决策',
        end: '结束'
      }
      return typeNames[type] || type
    }

    const getProcessIcon = (type) => {
      const icons = {
        appraisal: 'el-icon-document-checked',
        damage: 'el-icon-warning'
      }
      return icons[type] || 'el-icon-document'
    }

    const getDeadlineType = (urgency) => {
      const types = {
        low: 'info',
        normal: 'primary',
        high: 'warning',
        urgent: 'danger'
      }
      return types[urgency] || 'primary'
    }



    const getEventName = (event) => {
      const names = {
        created: '创建',
        assigned: '分配',
        started: '开始',
        completed: '完成',
        paused: '暂停',
        submitted: '提交',
        approved: '通过',
        rejected: '拒绝'
      }
      return names[event] || event
    }

    const getPreviewTitle = () => {
      return currentTemplate.value.title.replace(/\{\{节点名称\}\}/g, '案件受理')
    }

    const getPreviewContent = () => {
      return currentTemplate.value.content
        .replace(/\{\{案件编号\}\}/g, 'PJ2024001')
        .replace(/\{\{节点名称\}\}/g, '案件受理')
        .replace(/\{\{当事人\}\}/g, '张三')
        .replace(/\{\{操作人\}\}/g, '李四')
        .replace(/\{\{时间\}\}/g, new Date().toLocaleString())
    }

    return {
      // 数据
      activeModule,
      modules,
      processCategories,
      deadlineRules,
      deadlineStats,
      businessNodes,
      recipientGroups,
      notificationMethods,
      messageTemplates,
      currentTemplate,
      selectedNodes,
      selectedMethods,
      activeTemplate,
      editingNode,
      editingDeadline,
      nodeDialogVisible,
      deadlineDialogVisible,
      
      // 可视化流程设计器数据
      selectedTemplate,
      workflowNodes,
      connections,
      selectedNode,
      selectedConnection,
      selectedNodeData,
      zoomLevel,
      tempConnection,
      nodeTypes,
      processTemplates,
      canvas,

      // 方法
      switchModule,
      
      // 可视化流程设计器方法
      addNode,
      selectNode,
      deselectNode,
      deselectAll,
      deleteNode,
      updateNodeData,
      getNodeIcon,
      getNodeLabel,
      getResponsibleName,
      startNodeDrag,
      startConnection,
      getConnectionPath,
      clearCanvas,
      autoLayout,
      zoomIn,
      zoomOut,
      loadTemplate,
      saveWorkflow,
      previewWorkflow,
      addDeadlineRule,
      editDeadlineRule,
      saveDeadlineRule,
      deleteDeadlineRule,
      testReminder,
      configureNotification,
      updateEscalation,
      batchSetDeadlines,
      viewDeadlineStats,
      toggleNodeSelection,
      toggleMethodSelection,
      toggleRecipientGroup,
      switchTemplate,
      addTemplate,
      saveNotificationConfig,
      previewNotification,
      resetConfig,
      addNotificationRule,
      manageTemplates,
      testNotification,

      // 辅助方法
      getNodeTypeName,
      getProcessIcon,
      getDeadlineType,
      getEventName,
      getPreviewTitle,
      getPreviewContent
    }
  }
}
</script>

<style scoped>
.workflow-settings {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

/* 页面头部 */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 24px;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 8px 0;
}

.page-description {
  color: #6b7280;
  margin: 0;
  font-size: 14px;
}

/* 主要内容 */
.main-content {
  display: flex;
  gap: 20px;
  height: calc(100vh - 140px);
}

/* 左侧导航 */
.sidebar {
  width: 240px;
  background: white;
  border-radius: 12px;
  padding: 20px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background-color: #f3f4f6;
}

.nav-item.active {
  background-color: #eff6ff;
  border-left-color: #3b82f6;
  color: #3b82f6;
}

.nav-item i {
  font-size: 18px;
}

.nav-item span {
  font-weight: 500;
}

/* 右侧内容区 */
.content-area {
  flex: 1;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.module-content {
  padding: 24px;
  height: 100%;
  overflow-y: auto;
}

/* 模块头部 */
.module-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.module-header h2 {
  font-size: 20px;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 4px 0;
}

.module-header p {
  color: #6b7280;
  margin: 0;
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* 可视化流程设计器样式 */
.workflow-designer {
  display: flex;
  height: calc(100vh - 200px);
  background: #f5f7fa;
  border-radius: 8px;
  overflow: hidden;
}

.node-toolbar {
  width: 250px;
  background: white;
  border-right: 1px solid #e4e7ed;
  padding: 16px;
  overflow-y: auto;
}

.toolbar-section {
  margin-bottom: 24px;
}

.toolbar-section h4 {
  margin: 0 0 12px 0;
  color: #303133;
  font-size: 14px;
  font-weight: 600;
}

.node-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.node-btn {
  justify-content: flex-start;
  width: 100%;
  border: 1px solid #dcdfe6;
  color: #606266;
}

.node-btn.start {
  border-color: #67c23a;
  color: #67c23a;
}

.node-btn.process {
  border-color: #409eff;
  color: #409eff;
}

.node-btn.decision {
  border-color: #e6a23c;
  color: #e6a23c;
}

.node-btn.end {
  border-color: #f56c6c;
  color: #f56c6c;
}

.tool-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.workflow-canvas {
  flex: 1;
  position: relative;
  background: #fafafa;
  overflow: hidden;
  cursor: crosshair;
}

.canvas-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    linear-gradient(#e5e7eb 1px, transparent 1px),
    linear-gradient(90deg, #e5e7eb 1px, transparent 1px);
  background-size: 20px 20px;
  opacity: 0.5;
}

.workflow-node {
  position: absolute;
  min-width: 200px;
  background: white;
  border: 2px solid #e4e7ed;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  cursor: move;
  transition: all 0.2s;
  z-index: 10;
}

.workflow-node:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.workflow-node.selected {
  border-color: #409eff;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}

.workflow-node.start {
  border-color: #67c23a;
}

.workflow-node.process {
  border-color: #409eff;
}

.workflow-node.decision {
  border-color: #e6a23c;
  border-radius: 50px;
}

.workflow-node.end {
  border-color: #f56c6c;
}

.node-header {
  display: flex;
  align-items: center;
  padding: 12px;
  background: #f8f9fa;
  border-bottom: 1px solid #e4e7ed;
  border-radius: 6px 6px 0 0;
}

.node-icon {
  margin-right: 8px;
  font-size: 16px;
}

.node-title {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  color: #303133;
}

.delete-btn {
  padding: 4px;
  width: 24px;
  height: 24px;
}

.node-body {
  padding: 12px;
}

.node-description {
  margin: 0;
  font-size: 12px;
  color: #606266;
  line-height: 1.4;
}

.node-footer {
  padding: 8px 12px;
  background: #f8f9fa;
  border-top: 1px solid #e4e7ed;
  border-radius: 0 0 6px 6px;
}

.node-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #909399;
}

.connection-points {
  position: absolute;
}

.connection-point {
  width: 12px;
  height: 12px;
  background: #409eff;
  border: 2px solid white;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
}

.connection-point:hover {
  transform: scale(1.2);
}

.connection-point.input {
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
}

.connection-point.output {
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
}

.connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.connections-layer path {
  pointer-events: stroke;
  cursor: pointer;
  stroke-width: 2;
  transition: stroke-width 0.2s;
}

.connections-layer path:hover {
  stroke-width: 4;
}

.connections-layer path.selected {
  stroke: #e6a23c;
  stroke-width: 3;
}

.temp-connection {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
}

.property-panel {
  width: 300px;
  background: white;
  border-left: 1px solid #e4e7ed;
  padding: 16px;
  overflow-y: auto;
}

.property-panel h4 {
  margin: 0 0 16px 0;
  color: #303133;
  font-size: 16px;
  font-weight: 600;
}

/* 流程管理样式 */
.process-list {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}

.category-section {
  margin-bottom: 32px;
  background: #f9fafb;
  border-radius: 8px;
  padding: 20px;
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.category-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
}

.node-count {
  color: #6b7280;
  font-size: 12px;
  background: #e5e7eb;
  padding: 2px 8px;
  border-radius: 12px;
}

.process-flow {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding: 16px 0;
}

.process-node {
  flex-shrink: 0;
  width: 180px;
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.3s ease;
}

.process-node:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.node-name {
  font-weight: 600;
  color: #1f2937;
  font-size: 14px;
}

.node-type {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  color: white;
  font-weight: 500;
}

.node-type.start { background: #10b981; }
.node-type.process { background: #3b82f6; }
.node-type.approval { background: #f59e0b; }
.node-type.decision { background: #8b5cf6; }
.node-type.end { background: #ef4444; }

.node-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #6b7280;
}

.detail-item i {
  font-size: 12px;
}

.connector {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.arrow {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 12px solid #d1d5db;
}

.category-actions {
  display: flex;
  gap: 12px;
}

/* 期限管理样式 */
.deadline-table {
  margin-bottom: 24px;
}

.process-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reminder-methods {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.method-tag {
  margin: 2px 0;
}

.deadline-stats {
  margin-top: 24px;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.stat-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
}

.stat-icon.warning { background: #f59e0b; }
.stat-icon.danger { background: #ef4444; }
.stat-icon.success { background: #10b981; }
.stat-icon.info { background: #3b82f6; }

.stat-content {
  flex: 1;
}

.stat-number {
  font-size: 24px;
  font-weight: 700;
  color: #1f2937;
  line-height: 1;
}

.stat-label {
  font-size: 14px;
  color: #6b7280;
  margin-top: 4px;
}

/* 通知管理样式 */
.notification-config {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.config-section {
  background: #f9fafb;
  border-radius: 8px;
  padding: 20px;
}

.config-section.full-width {
  grid-column: 1 / -1;
}

.config-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 16px 0;
}

.node-selector {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.node-item {
  background: white;
  border-radius: 6px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.node-item:hover {
  border-color: #e5e7eb;
}

.node-item.selected {
  border-color: #3b82f6;
  background: #eff6ff;
}

.node-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.node-info i {
  color: #3b82f6;
}

.node-events {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.recipient-config {
  max-height: 300px;
  overflow-y: auto;
}

.recipient-group {
  margin-bottom: 16px;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.member-count {
  font-size: 12px;
  color: #6b7280;
  background: #e5e7eb;
  padding: 2px 6px;
  border-radius: 8px;
}

.group-members {
  padding-left: 24px;
}

.notification-methods {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.method-item {
  background: white;
  border-radius: 6px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  gap: 12px;
}

.method-item:hover {
  border-color: #e5e7eb;
}

.method-item.selected {
  border-color: #3b82f6;
  background: #eff6ff;
}

.method-icon {
  width: 40px;
  height: 40px;
  background: #f3f4f6;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
}

.method-item.selected .method-icon {
  background: #3b82f6;
  color: white;
}

.method-info {
  flex: 1;
}

.method-name {
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 2px;
}

.method-desc {
  font-size: 12px;
  color: #6b7280;
}

.template-editor {
  background: white;
  border-radius: 8px;
  padding: 20px;
}

.template-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 12px;
}

.template-tab {
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  color: #6b7280;
}

.template-tab:hover {
  background: #f3f4f6;
}

.template-tab.active {
  background: #3b82f6;
  color: white;
}

.template-content {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
}

.template-form {
  flex: 1;
}

.template-preview {
  background: #f9fafb;
  border-radius: 8px;
  padding: 16px;
}

.template-preview h4 {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 12px 0;
}

.preview-content {
  background: white;
  border-radius: 6px;
  padding: 12px;
  border: 1px solid #e5e7eb;
}

.preview-title {
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 8px;
  font-size: 14px;
}

.preview-body {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.5;
  white-space: pre-line;
}

.config-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding-top: 24px;
  border-top: 1px solid #e5e7eb;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .config-grid {
    grid-template-columns: 1fr;
  }
  
  .template-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
    height: auto;
  }
  
  .sidebar {
    width: 100%;
  }
  
  .nav-menu {
    flex-direction: row;
    overflow-x: auto;
  }
  
  .process-flow {
    flex-direction: column;
    align-items: stretch;
  }
  
  .connector {
    transform: rotate(90deg);
    margin: 8px 0;
  }
  
  .stat-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 新增样式 */
.reminder-config {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reminder-note {
  margin-top: 8px;
  padding: 8px;
  background: #f0f9ff;
  border-radius: 4px;
  border-left: 3px solid #409eff;
}

.reminder-note .el-text {
  font-size: 12px;
}
</style>
